# TESTING_STRATEGY.md

Rule: **a test counts only if it was executed and its output was recorded.** "Should pass" is not a result.

## Layers

| # | Layer | Tool (proposed; confirm versions when scaffolding) | Runs |
|---|---|---|---|
| 1 | Type check | `tsc --noEmit` | pre-commit, CI |
| 2 | Lint | ESLint (with `react/no-danger`, `jsx-a11y`) | pre-commit, CI |
| 3 | Unit | Vitest: pricing quote display, date/TZ helpers, i18n completeness | CI |
| 4 | Integration | Vitest + local Supabase (CLI / Docker) | CI |
| 5 | API / RPC | Calls to `create_booking`, `quote_booking`, `transition_booking` against local DB | CI |
| 6 | Database | SQL tests (pgTAP): constraints, exclusion constraint, transition rules | CI |
| 7 | Authentication | Sign up, verify, sign in, reset, sign out, expired session | CI (E2E) |
| 8 | Authorization / RLS | Matrix: anon × customer A × customer B × staff × admin, against every table and RPC | CI |
| 9 | E2E | Playwright: browse → filter → book → see in account → admin confirms | CI on preview |
| 10 | Responsive | Playwright projects: 375×812, 768×1024, 1280×800; EN and AR | CI on preview |
| 11 | Accessibility | axe via Playwright; keyboard-only booking flow | CI |
| 12 | Performance | Lighthouse CI on key pages; bundle size budget | CI on preview |
| 13 | Production build | `build` + smoke test of the preview URL | Before every merge |

## Must-have scenarios (failure paths included)

**Booking**
- Return before or equal to pickup → rejected, with a clear message (EN and AR)
- Pickup in the past (server time) → rejected
- Overlapping booking on the same car → rejected; adjacent bookings (return == next pickup) → allowed
- Two concurrent requests for the same slot → exactly one succeeds
- A tampered price or status in the request → ignored or rejected
- An illegal status transition (e.g. `completed→active`) → rejected
- Network failure on submit → error state, no success screen, no duplicate booking on retry (idempotency key)

**Security**
- Customer B cannot read, update, or cancel customer A's booking
- Anon cannot read customers or bookings
- A non-staff user cannot call admin RPCs or update vehicles
- An XSS payload in the name field renders as text in the admin view
- The client bundle contains no secret key (grep the build output)

**i18n / RTL**
- Every key exists in both `en` and `ar` (unit test)
- AR screenshots: layout mirrored, arrows flipped, numbers readable

## Existing tooling in the current cloud workspace (verified 2026-11-30)

Node 22.23.5, npm 10.9.9, pnpm 10.28.0, TypeScript 6.0.3, Playwright 1.63.0 (Node and Python), `@playwright/mcp` 0.0.68, Docker 29.9.3, psql 16.15. **Not present:** Supabase CLI and Vercel CLI. Package installs are currently blocked by the account's network setting.
