Skip to content

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

Closed
sathyaprakash000 wants to merge 2 commits into
mainfrom
ci/run-tests
Closed

ci(test): run unit tests in CI + add backend test suite (P0 #9)#8
sathyaprakash000 wants to merge 2 commits into
mainfrom
ci/run-tests

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.

Changes

  • CI: backend job runs npm test; frontend job runs npm run test:unit (Playwright e2e intentionally stays out of the PR gate to keep it fast/hermetic).
  • backend: npm testnode --test test/ — Node 20's built-in test runner, zero new dependencies (matters for a source-available repo / supply chain).
  • 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 overrides.
    • access: adminOnly lets admins through, 403s bda_sales/viewer.
    • webhookSignature: verifyMetaSignature valid / forged / missing-secret(null) / malformed-header / no-body; safeEqual.
  • 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)
  • node --check passes on webhook.js + webhookSignature.js.

sathyaprakash000 and others added 2 commits May 25, 2026 03:40
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).
- 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>
gitleaks flagged the hardcoded FORGECRM_ENCRYPTION_KEY test fixture
(generic-api-key rule). Generate the key at runtime via crypto.randomBytes
instead of a literal, and rename the EAA*-prefixed sample tokens so no scanner
mistakes them for real Meta access tokens. No change to what's tested.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: KingArthur000 <sathyaprakashelango@gmail.com>
@sathyaprakash000

Copy link
Copy Markdown
Contributor Author

Superseded by a squashed, gitleaks-clean branch (the original branch's first commit contained a secret-shaped test literal that gitleaks flagged in history). Re-opened as a single clean commit.

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