ci(test): run unit tests in CI + add backend test suite (P0 #9) - #9
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) andnpm run build(frontend), so the 3 existing frontend vitest suites never ran and the backend had zero tests.Changes
npm test; frontend job runsnpm run test:unit(Playwright e2e intentionally stays out of the PR gate).npm test→node --test test/— Node 20's built-in runner, zero new dependencies (supply-chain conscious for source-available).crypto: encrypt/decrypt round-trip, random-IV uniqueness, tamper →null, garbage →null,maskSecret.permissions:isAdmin,hasPermission(admin vsbda_sales),effectivePagesgrant/revoke.access:adminOnlylets admins through, 403sbda_sales/viewer.webhookSignature:verifyMetaSignaturevalid / forged / null-secret / malformed / no-body;safeEqual.safeEqual+verifyMetaSignatureintoutil/webhookSignature.jsso they're testable without importing the BullMQ/Redis side-effects of the webhook route.webhook.jsimports them — no behaviour change.Verification (local, mirrors CI)
npm ci --omit=dev && npm test→ 20/20 passnpm ci && npm run test:unit→ 51/51 pass (3 files)