Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 87 additions & 46 deletions .github/workflows/cpanel_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,87 @@
name: Deploy to cPanel
on:
push:
branches:
- main
jobs:
deploy:
name: 🚀 Deploy via FTP to cPanel
runs-on: ubuntu-latest
steps:
- name: Checkout latest code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
# Remove or fix the cache-dependency-path
# Option 1: Remove cache entirely (simplest)
# Option 2: Fix the path (see below)

- name: Install dependencies and build
env:
# This maps the GitHub Repository Variiable to the environment variable Vite needs
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL }}
run: |
npm ci
npm run build

- name: 📂 Upload files to cPanel via FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
port: 21
protocol: ftps
security: loose
server-dir: /
local-dir: ./dist/
exclude: |
**/.git*
**/.git*/**
**/.github*/**
**/node_modules/**
**/README.md
name: Quality checks and cPanel deployment

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read

jobs:
quality:
name: quality
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: |
package-lock.json
backend/package-lock.json

- name: Install frontend dependencies
run: npm ci

- name: Install backend dependencies
run: npm ci --prefix backend

- name: Lint
run: npm run lint

- name: Test
run: npm test

- name: Build frontend
env:
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL }}
run: npm run build

- name: Upload frontend build
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: dist/
if-no-files-found: error
retention-days: 1

deploy:
name: Deploy via FTP to cPanel
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: quality
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download frontend build
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: dist/

- name: Upload files to cPanel via FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
port: 21
protocol: ftps
security: loose
server-dir: /
local-dir: ./dist/
exclude: |
**/.git*
**/.git*/**
**/.github*/**
**/node_modules/**
**/README.md
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,22 @@ The React Compiler is not enabled on this template because of its impact on dev
## Expanding the ESLint configuration

If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.

## Project quality checks

Install dependencies from the repository root and backend directory:

```bash
npm ci
npm ci --prefix backend
```

Run the checks used by CI:

```bash
npm run lint
npm test
npm run build
```

`npm test` runs the backend suite and frontend component tests. Use `npm run test:frontend:watch` while developing frontend tests.
2 changes: 1 addition & 1 deletion backend/src/middlewares/errorHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const errorHandler = (err, req, res, next) => {
export const errorHandler = (err, req, res, _next) => {
console.error("Unhandled Server Error:", err);

const statusCode = err.status || err.statusCode || 500;
Expand Down
44 changes: 43 additions & 1 deletion backend/tests/accessPolicy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ const makeQuery = (table) => {
return { data: single ? selected[0] || null : selected, error: null, count: selected.length };
}
if (action === "delete") {
const deleted = selected.map((row) => ({ ...row }));
store[table] = rows.filter((row) => !selected.includes(row));
return { data: null, error: null, count: selected.length };
return { data: single ? deleted[0] || null : deleted, error: null, count: selected.length };
}

if (head) {
Expand Down Expand Up @@ -224,6 +225,17 @@ test("public signup is closed and intake cannot assign or pre-mark submissions",
assert.equal(payload.data.followUpStatus, "pending");
assert.equal(payload.data.assignedTo, null);
});

await t.test("intake rejects missing required fields without inserting a submission", async () => {
const countBefore = store.first_timers.length;
const response = await request("/first-timers", {
method: "POST",
body: { fullName: "Incomplete Guest", phoneNumber: "789" },
});

assert.equal(response.status, 400);
assert.equal(store.first_timers.length, countBefore);
});
});

test("anonymous, disabled, and role-restricted requests are rejected", async (t) => {
Expand Down Expand Up @@ -318,10 +330,25 @@ test("pastors have oversight access while administrators retain account and expo
assert.equal(assignmentResponse.status, 200);
});

await t.test("metrics return counts based on all submissions", async () => {
const response = await request("/metrics", { id: adminId });
const payload = await response.json();

assert.equal(response.status, 200);
assert.equal(payload.data.totalSubmissions, 3);
assert.equal(payload.data.followedUp, 2);
assert.equal(payload.data.topDiscoverySource, "Not Specified");
assert.equal(payload.data.topDiscoveryCount, 3);
});

await t.test("administrators can export submissions", async () => {
const response = await request("/first-timers/export", { id: adminId });
const csv = await response.text();

assert.equal(response.status, 200);
assert.match(response.headers.get("content-type"), /text\/csv/);
assert.match(csv, /Full Name/);
assert.match(csv, /Assigned Guest/);
});

await t.test("admins can provision accounts and deactivate them immediately", async () => {
Expand Down Expand Up @@ -453,3 +480,18 @@ test("password changes and role changes invalidate prior sessions", async (t) =>
assert.equal(metricsResponse.status, 200);
});
});

test("administrators can delete submissions and missing submissions return 404", async () => {
const response = await request(`/first-timers/${unassignedSubmissionId}`, {
id: adminId,
method: "DELETE",
});

assert.equal(response.status, 200);

const missingResponse = await request(`/first-timers/${unassignedSubmissionId}`, {
id: adminId,
method: "DELETE",
});
assert.equal(missingResponse.status, 404);
});
29 changes: 18 additions & 11 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,32 @@ import reactRefresh from 'eslint-plugin-react-refresh'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
globalIgnores(['dist']),
globalIgnores(['dist', 'coverage']),
{
files: ['**/*.{js,jsx}'],
extends: [
js.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
extends: [js.configs.recommended],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^[A-Z_]' }],
},
},
{
files: ['src/**/*.{js,jsx}'],
extends: [reactHooks.configs.flat.recommended, reactRefresh.configs.vite],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
rules: {
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
},
{
files: ['backend/**/*.js', '*.config.js'],
languageOptions: {
globals: globals.node,
},
},
])
Loading
Loading