Skip to content

ci(test): run unit tests in CI + add backend test suite (P0 #9) - #9

Merged
sathyaprakash000 merged 1 commit into
mainfrom
ci/unit-tests-gate
May 25, 2026
Merged

ci(test): run unit tests in CI + add backend test suite (P0 #9)#9
sathyaprakash000 merged 1 commit into
mainfrom
ci/unit-tests-gate

Conversation

@sathyaprakash000

@sathyaprakash000 sathyaprakash000 commented May 25, 2026

Copy link
Copy Markdown
Contributor

What & why

Closes the last P0 from the source-available readiness review (lane 26): CI never executed any tests. It ran only node --check (backend) and npm run build (frontend), so the 3 existing frontend vitest suites never ran and the backend had zero tests.

Supersedes #8 — same change set, squashed into one commit so the gitleaks full-history scan stays clean (the old branch's first commit contained a secret-shaped test fixture).

Changes

  • CI: backend job runs npm test; frontend job runs npm run test:unit (Playwright e2e intentionally stays out of the PR gate).
  • backend: npm testnode --test test/ — Node 20's built-in runner, zero new dependencies (supply-chain conscious for source-available).
  • backend tests (20 passing):
    • crypto: encrypt/decrypt round-trip, random-IV uniqueness, tamper → null, garbage → null, maskSecret.
    • permissions: isAdmin, hasPermission (admin vs bda_sales), effectivePages grant/revoke.
    • access: adminOnly lets admins through, 403s bda_sales/viewer.
    • webhookSignature: verifyMetaSignature valid / forged / null-secret / malformed / no-body; safeEqual.
    • Fixtures generate keys at runtime and avoid token-shaped literals (gitleaks-safe).
  • refactor: extracted safeEqual + verifyMetaSignature into util/webhookSignature.js so they're testable without importing the BullMQ/Redis side-effects of the webhook route. webhook.js imports them — no behaviour change.

Verification (local, mirrors CI)

  • backend: npm ci --omit=dev && npm test20/20 pass
  • frontend: npm ci && npm run test:unit51/51 pass (3 files)

CI previously only ran `node --check` (backend) and `npm run build` (frontend) —
the 3 existing frontend vitest suites never ran and the backend had no tests.

- CI: backend job now runs `npm test`; frontend job runs `npm run test:unit`
  (the Playwright e2e stays out of the PR gate).
- backend: add `npm test` -> `node --test test/` (Node's built-in runner, zero
  new dependencies — important for a source-available repo).
- backend tests (20): crypto encrypt/decrypt round-trip + tamper/garbage
  handling + maskSecret; permissions isAdmin/hasPermission/effectivePages incl.
  grant/revoke; access.adminOnly allows admin / 403s non-admin; webhook
  X-Hub-Signature-256 verify (valid/forged/missing-secret/malformed/no-body).
  Test fixtures generate any key at runtime and avoid token-shaped literals so
  the gitleaks history scan stays clean.
- Extract the webhook signature helpers (safeEqual, verifyMetaSignature) into
  util/webhookSignature.js so they're unit-testable without pulling in the
  BullMQ/Redis side-effects of the route module. webhook.js imports them; no
  behaviour change.

Closes the last P0 from the readiness review (lane 26).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: KingArthur000 <sathyaprakashelango@gmail.com>
@sathyaprakash000
sathyaprakash000 merged commit ad028d1 into main May 25, 2026
9 of 10 checks passed
@sathyaprakash000
sathyaprakash000 deleted the ci/unit-tests-gate branch May 25, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant