2.4 KiB
2.4 KiB
Testing
Test infrastructure and manual recipes for the Africa Alert PWA. Owned by the tester rein.
Status
- No test framework installed yet — bootstrap is the tester's first sprint.
- Target stack: Vitest (client + server) + Supertest (server) + Playwright (E2E, when needed).
When you add a new feature
- Producer writes the feature.
- Producer hands off to
testerwith a one-line description of the happy path and at least one adversarial path. testerwrites unit + integration tests, runs them, and reports coverage to the orchestrator.code-revieweraudits the tests for circular assertions and demands real-run evidence for the user path.
Manual recipes (for things that don't auto-test credibly)
Paynow webhook idempotency
- Initiate a payment via the UI or
POST /api/payments/initiatewith a small amount. - Capture the returned
payment_id. curl -X POST http://localhost:3001/api/payments/webhook -d '{ "payment_id": "<id>", "status": "paid" }'— twice in a row.- Verify the database has exactly one row in
paymentsfor thatstudent_fee_idandstudent_fees.status = 'paid'. Two POSTs, one state change.
Sync engine round-trip
- Set
SUPABASE_URLto a local stub (e.g.http://localhost:4000/rest/v1/) andSUPABASE_KEYto anything truthy. POST /api/sync/force.- Inspect
sync_logs— every table should besuccessorskipped(offline), nofailedfor a clean round. GET /api/sync/status→lastSyncupdated,totalPendingdecreased.
Offline PWA
npm run devinclient/andserver/.- Open the app, log in, navigate to a couple of pages (warms the service worker cache).
- DevTools → Application → Service Workers → confirm
sw.jsisactivated. - DevTools → Network → Offline.
- Reload. The shell should still render; cached pages should still open; the dashboard fetch may fail with a clear offline banner (this is fine — the design point is "no white screen of death").
CI (planned)
GitHub Actions workflow at .github/workflows/test.yml (when the user adds it):
- Matrix: Node 20.x
- Steps: install (client + server),
npm testin each, build client.
Test data isolation
- Use
data/school.test.dbfor integration tests, never the realdata/school.db. - Each test or describe block gets a fresh DB file (or in-memory
:memory:). - Don't mock the DB schema — copy the relevant
CREATE TABLEblock fromserver/src/database/init.js.