Testing¶
Tests check behaviour, not implementation: which slots come out, what's in the database, which Google calls and emails happened. They should survive refactors.
Unit and service tests (Vitest)¶
- Run against a real Postgres database,
meetings_teston the same server as yourDATABASE_URL. It's created and migrated automatically; tables are truncated before each test. - Google is the in-memory fake (
GOOGLE_FAKE=1), which records created events and sent emails so tests can assert on them, and can be told to fail. - Sites come from
tests/brands.json. - Files run one after another (they share the database).
| File | Covers |
|---|---|
slots.test.ts |
Slot calculator: hours, DST, buffers, notice, horizon, timezones. |
meetings.test.ts, recurring-sync.test.ts |
Creating, updating, cancelling, recurring meetings, sync. |
booking.test.ts |
Public booking, double-booking, rollback, reschedule/cancel tokens, validation. |
clients.test.ts |
Clients, contacts, matching. |
security.test.ts |
Access control, token handling, input hardening, bot limits. |
brands.test.ts |
Sites: host mapping, owners, isolation, colour warnings. |
notify.test.ts |
Reminders and daily emails. |
photo.test.ts, profile.test.ts |
Photos, name and headline. |
Browser tests (Playwright)¶
Playwright builds the app and runs the same server.js the production image runs, on port 3100, against a fresh meetings_e2e database with fake Google. Sites come from e2e/brands/brands.json; *.localhost names let one server play several sites.
Tests sign in through the test-only login, /api/auth/test-login?email=….
Writing tests¶
- Prefer a service test in
tests/for logic, and an e2e test only for what needs a browser: navigation, forms, client-side behaviour. - In e2e tests, find elements by role and label (
getByRole,getByLabel), as a screen reader would. If that's hard, the UI probably needs a better label. - Don't depend on the time of day: pick days that are fully in the future (see
e2e/booking.spec.ts).