mirror of
https://github.com/tiennm99/bsk.git
synced 2026-08-03 14:22:38 +00:00
The repo had zero tests despite PLAN §7 mandating them. - 97 unit tests over the pure logic: checkup/customer/catalog/template Zod schemas, parseNum, computeAge, and invoice math - extracted lib/billing/totals.ts (sumLineTotals/formatVnd) so invoice math is testable, and refactored the invoice route + dashboard to use it - 16 Playwright smoke tests that need no database: auth gates redirect to sign-in, VI-default rendering, password-reveal toggle, /en locale, 404 - playwright.config passes placeholder env inline via webServer.env so no env file is ever needed; pnpm test wired into CI (E2E stays local) tests/e2e/README.md documents the seeded-data prerequisites for the full queue -> checkup -> prescription -> paid -> invoice happy path, which is blocked on a provisioned Supabase project rather than faked with skipped tests.
E2E Test Constraints
This directory contains infrastructure-level smoke tests for the BSK clinic app. These tests are designed to run without a live Supabase instance by only asserting on public, unauthenticated routes.
What's Tested
- Auth gate (
auth-gate.spec.ts): Unauthenticated access to/dashboard,/queue,/patientsredirects to sign-in. - Sign-in page (
sign-in-page.spec.ts): Form rendering, input focus, password reveal toggle, basic interactivity. - i18n & 404 (
i18n-and-404.spec.ts): English/Vietnamese locale rendering, not-found page localization.
What's NOT Tested (Blocked)
The complete happy-path user journey is blocked on a provisioned Supabase project with the following seed data:
-
Patient registration → queue number
- Requires: clinic settings (clinic name), shifts, patients table, queue logic
- Spec outline:
register-patient.spec.ts(not yet written)
-
Call patient → open checkup form
- Requires: doctor assignments, checkup status workflows
- Spec outline:
call-patient.spec.ts(not yet written)
-
Save checkup → compose prescription
- Requires: templates, medicines catalog, services catalog
- Spec outline:
save-checkup-and-prescribe.spec.ts(not yet written)
-
Mark paid → generate invoice PDF
- Requires: payment status workflow, PDF rendering
- Spec outline:
invoice-workflow.spec.ts(not yet written)
To Enable Full E2E Testing
Provision a Supabase project with:
- All migrations from
supabase/migrations/applied - Seed data:
- At least one clinic (in clinic_settings)
- One admin user + one doctor + one cashier (in auth.users + custom claims)
- 5–10 test patients (in customers table)
- 3 shifts (in shifts table)
- 5–10 medicines (in medicines table)
- 3–5 services (in services table)
Then:
- Set
NEXT_PUBLIC_SUPABASE_URLandNEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYinplaywright.config.ts(underwebServer.env). - Set
SUPABASE_SECRET_KEYandUPSTASH_REDIS_REST_URL/UPSTASH_REDIS_REST_TOKEN(or mock them). - Write the full journey specs in this directory.
Running Tests
# All E2E tests (smoke suite only until Supabase is provisioned)
pnpm test:e2e
# Watch mode
pnpm test:e2e --watch
# With UI
pnpm test:e2e --ui
# Specific file
pnpm test:e2e auth-gate.spec.ts
Debugging
# Show browser
HEADED=1 pnpm test:e2e
# Slow motion (100ms per step)
pnpm test:e2e --headed --workers=1 --trace=on