# Testing Strategy and Acceptance Criteria

> **Status:** the Phase 1–7 suites are **implemented and passing** (reports in §8–§17; §17 is the latest full run, Phase 7, with the 44 px touch-target check). Test tables for later phases are still **PLANNED**.
> Baseline: SRS §18 and §18.1, Master Prompt §22. Decision IDs refer to `docs/DECISIONS.md`.

## 1. Test levels and tools

| Level                       | Tool                                                                              | Scope                                                                                                                                                                                                                           |
| --------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Unit (server)               | Vitest                                                                            | Business-date maths, membership state transitions, payment calculations and status rules, overpayment and future-date guards, retry classifier, permission matrix helpers, phone normalisation, password policy, Zod validators |
| API integration             | Vitest + Supertest + `mongodb-memory-server` (replica-set mode, for transactions) | Auth, sessions, authorization (403 matrix), data integrity, transactions, concurrency, deletion dependencies, outbox idempotency                                                                                                |
| Frontend unit and component | Vitest + Testing Library                                                          | Forms and validation messages, role-based navigation, permission-gated UI, loading, empty and error states, RTL switching                                                                                                       |
| End-to-end                  | Playwright (Chromium + WebKit)                                                    | The critical workflows in §4, with the WhatsApp mock adapter                                                                                                                                                                    |
| Visual and responsive       | Playwright screenshots                                                            | Every main screen at **360, 375, 390, 414, 768 and 1280 px**, in **light and dark**, plus spot checks in Urdu (RTL)                                                                                                             |
| Manual                      | The user or client on real phones                                                 | UAT on Android Chrome and iOS Safari. Real WhatsApp delivery once credentials exist                                                                                                                                             |

**Environment note.** Claude's workspace has restricted network access. If the MongoDB in-memory binary or the Playwright browsers cannot be downloaded there, the affected suites are reported as **Blocked (environment)**, never as Passed, and the commands are handed over so they can be run locally or in CI.

## 2. Rules

- No feature is marked complete until its tests pass and its result is recorded (Prompt §21).
- A mocked integration is never reported as working (Prompt §22). WhatsApp tests against the mock are labelled _"mock"_.
- Critical and high-priority bugs are fixed before a phase is closed.
- Every test report uses four outcomes: **Passed · Failed · Blocked · Not tested**.

## 3. Key unit-test tables

### 3.1 Membership dates (D-25, C-12)

| Start      | Plan           | Expected end             |
| ---------- | -------------- | ------------------------ |
| 2026-11-01 | 1 month        | 2026-11-30 (SRS example) |
| 2026-11-15 | 1 month        | 2026-12-14               |
| 2027-01-31 | 1 month        | 2027-02-28               |
| 2028-01-31 | 1 month        | 2028-02-29 (leap year)   |
| 2027-01-30 | 1 month        | 2027-02-28               |
| 2028-02-29 | 1 month        | 2028-03-28               |
| 2026-12-01 | 3 months       | 2027-02-28               |
| 2026-11-01 | 12 months      | 2027-10-31               |
| 2026-11-01 | custom 30 days | 2026-11-30               |
| 2026-11-01 | custom 1 day   | 2026-11-01               |

**Early renewal.** The current membership ends 2026-11-30 and the member renews on 2026-11-20. The new membership starts 2026-12-01 with status Upcoming, and becomes Active on 2026-12-01 (Prompt §10.3, C-12).
**Late renewal.** The membership expired 2026-11-30 and the member renews 2026-12-05. The new membership starts 2026-12-05 with status Active.
**Timezone.** At 23:30 Asia/Karachi (18:30 UTC), `today()` returns the Karachi date. The expiry job at 00:05 PKT expires memberships whose end date was yesterday.

### 3.2 Payments (C-13 – C-15, D-31 – D-35)

| Scenario                                                  | Expected                                                                                |
| --------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| Total 5,000; verified 2,000                               | Paid 2,000 · balance 3,000 · **Partially Paid**                                         |
| Then verified 1,500                                       | Paid 3,500 · balance 1,500 · same summary, 2 entries, 2 receipts (Prompt §11.3 example) |
| Total 5,000; only a pending 5,000 online entry            | Paid 0 · balance 5,000 · **Pending**                                                    |
| No entries                                                | **Unpaid**                                                                              |
| Verified 5,000                                            | **Paid** · balance 0                                                                    |
| Verified 3,000 + pending 1,000, then a new entry of 1,500 | Rejected as `OVERPAYMENT`                                                               |
| Payment date tomorrow                                     | Rejected as `FUTURE_PAYMENT_DATE`                                                       |
| Payment date last month                                   | Accepted. `recordedAt` = now (C-15)                                                     |
| Correction without a reason                               | Rejected as `REASON_REQUIRED`                                                           |
| Correction of a verified entry with a receipt             | Old receipt void, new number issued, correction log written                             |
| Two concurrent entries on the same summary                | One succeeds. The other gets `VERSION_CONFLICT` or a correct retry. No overpayment      |
| Renewal with an old balance outstanding                   | The new summary is separate. The old balance is unchanged (C-15)                        |

### 3.3 Notifications (C-26, D-47)

- A transient error leads to retries at +15, +30 and +45 minutes. After the 3rd retry fails → Failed and `needsFollowUp`.
- A permanent error (invalid number, template rejected) → Failed immediately, with no retries.
- The same idempotency key enqueued twice → one notification.
- Running the dispatcher twice at once → each notification is sent once.
- A member who opts out after a message is queued → blocked at dispatch.

## 4. Acceptance scenarios (SRS §18.1, numbered here AC-01 to AC-26)

| ID    | Scenario                                                                                                                                            | Level                      |
| ----- | --------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
| AC-01 | A visitor submits a valid inquiry, and it appears only in the Admin workflow. A Trainer gets 403 on the inquiry endpoints                           | API + E2E                  |
| AC-02 | A duplicate inquiry phone triggers the warning, submission is still possible, and no private record is exposed                                      | API + E2E                  |
| AC-03 | An Admin converts an inquiry and the member fields are prefilled. Consent carries over with its history                                             | E2E                        |
| AC-04 | Deleting the original inquiry does not affect the converted member or any of its history                                                            | API                        |
| AC-05 | Admin and Trainer can add and edit members. A duplicate phone is prevented                                                                          | API + E2E                  |
| AC-06 | Member IDs are unique, including under concurrent creation. Photo upload and replace work for both roles. Photo removal is Admin-only               | API                        |
| AC-07 | Archiving is blocked while a membership is active. Restore reuses the same record and ID. **Both Admin and Trainer** can archive and restore (C-38) | API                        |
| AC-08 | An Admin creates plans and sets a custom price with a reason that is audited. A Trainer gets 403                                                    | API                        |
| AC-09 | Activation works only after a verified partial or full payment (both roles)                                                                         | API + E2E                  |
| AC-10 | Date calculations follow the calendar-month rule and Asia/Karachi (§3.1)                                                                            | Unit                       |
| AC-11 | Expiry makes the member Inactive. A new activation makes them Active again                                                                          | Unit + API (job)           |
| AC-12 | Every renewal creates a new membership record. Earlier history is kept                                                                              | API                        |
| AC-13 | One payment summary per membership. Each verified event has its own entry and receipt                                                               | API                        |
| AC-14 | A pending or unverified payment does not reduce the outstanding balance                                                                             | Unit + API                 |
| AC-15 | Overpayment and future dates are blocked. Corrections need a reason and keep history                                                                | Unit + API                 |
| AC-16 | Workout-note author permissions and the Admin override work. Deletion is a soft delete                                                              | API                        |
| AC-17 | Only Admin manages templates. A Trainer can only view and send                                                                                      | API                        |
| AC-18 | Opt-out blocks all automatic and manual sends, and receipt sharing                                                                                  | API                        |
| AC-19 | Temporary failures retry every 15 minutes up to 3 times. Permanent failures do not retry                                                            | Unit + API                 |
| AC-20 | A Trainer sees only the notifications they sent. An Admin sees all                                                                                  | API                        |
| AC-21 | Reports support custom ranges, PDF output and the Cash/Online filter. Income and expenses are separate, with no net profit                          | API + manual PDF check     |
| AC-22 | A member data export is PDF only, after password confirmation, and is logged                                                                        | API                        |
| AC-23 | Deletion safeguards, dependency checks and no-cascade are enforced for every deletable type                                                         | API                        |
| AC-24 | Deactivating a Trainer revokes their sessions immediately. Deleting a Trainer keeps the history                                                     | API                        |
| AC-25 | The Admin dashboard shows upcoming expiries and the Trainer summary. The Trainer dashboard does not have the widget                                 | API + E2E                  |
| AC-26 | Backups run weekly, 8 are kept, and the operator can restore (in non-production)                                                                    | Script test + manual drill |

## 5. Additional mandatory tests (SRS §18, Prompt §22)

- **Auth.** Login with the username and with the email; logout; session expiry after 90 days of inactivity (time mocked); rotation; force logout; deactivation; Admin email reset; Trainer self-password-change gets 403; first-Admin setup once only (then 410); progressive delay timings; no permanent lockout.
- **Authorization matrix.** An automated test iterates every route with its permission key and checks the role outcomes (Admin, Trainer, anonymous).
- **CSRF.** A state-changing request with a foreign or missing Origin → 403.
- **Cloudinary.** The old asset is removed only after commit. A failed clean-up is recorded and retried (mocked SDK, with live checks in staging).
- **WhatsApp.** Template rejection; no consent; opt-out; permanent failure; transient retries; webhook signature valid or invalid; status idempotency.
- **Localisation.** No missing keys in `ur.json` (scripted check). RTL layout has no overflow at 360px.
- **Responsive.** At 360–414px: no horizontal page scroll, no clipped buttons, no overlapping fixed bars, all targets at least 44px, every dialog usable, charts inside their container.
- **Themes.** Contrast in light and dark meets WCAG AA for body text (an automated axe check on the main screens).

## 6. Reports

Each phase checkpoint appends a section to `PROJECT_STATUS.md` with:

```
Suite | Passed | Failed | Blocked | Not tested | Notes
```

and lists any acceptance scenarios touched by the phase, with their outcomes.

## 7. Commands

```
npm run test:server      # server unit + API integration (Vitest + Supertest + in-memory replica set)
npm run test:client      # client unit (Vitest + Testing Library, jsdom)
npm run test:e2e         # Playwright: end-to-end flow + @visual responsive/theme suite
npm run i18n:check -w client
npm run lint
```

Workspace-specific variables: `MONGOMS_SYSTEM_BINARY` (local mongod for server tests), `PLAYWRIGHT_CHROME` (installed Chrome), `E2E_MONGODB_URI` (replica set for E2E; the `gms_e2e` database is dropped at the start of every run).

## 8. Phase 1 test report (17 Nov 2026)

| Suite                                                                                                                                                                                              | Passed | Failed | Blocked | Not tested | Notes                                                                                     |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ | ------- | ---------- | ----------------------------------------------------------------------------------------- |
| Server unit (password policy, delay, permission matrix, env, log privacy)                                                                                                                          | 15     | 0      | 0       | 0          |                                                                                           |
| Server API integration (setup, login, sessions, rotation, expiry, CSRF, profile, password change/reset, staff CRUD, deactivation, force logout, deletion, audit immutability, route-access matrix) | 31     | 0      | 0       | 0          | Real MongoDB 8.3 replica set, in memory                                                   |
| Client unit (i18n parity, RTL switch, nav visibility, error helpers, DangerConfirm, route guard)                                                                                                   | 8      | 0      | 0       | 0          |                                                                                           |
| E2E flow (setup once → create Trainer → Trainer limits → deactivation ends session)                                                                                                                | 4      | 0      | 0       | 0          | Built client + real API                                                                   |
| Visual/responsive (8 screens × 6 widths × 2 themes, dialogs/menus at 360px, Urdu RTL at 390px)                                                                                                     | 14     | 0      | 0       | 0          | Automatic checks: no horizontal overflow, no control under 36px; 106 screenshots reviewed |
| Lint (ESLint) / build (Vite)                                                                                                                                                                       | ✓      | —      | —       | —          |                                                                                           |
| Real SMTP delivery                                                                                                                                                                                 | —      | —      | —       | ✓          | P-07. The console transport was verified only                                             |
| Atlas, Render, Vercel                                                                                                                                                                              | —      | —      | —       | ✓          | P-02 to P-04. Not deployed                                                                |
| Real phones (iOS Safari, Android Chrome), WebKit engine                                                                                                                                            | —      | —      | —       | ✓          | Only Chrome device-width emulation is available here. **Needs your check on real phones** |

Acceptance scenarios touched in Phase 1: **AC-24** (deactivating a Trainer revokes their sessions at once; deleting keeps the history), **Passed**. The first-Admin setup, login/session and authorization tests from §5 also pass.

## 9. Phase 2 test report (17 Nov 2026)

| Suite                                                                                                                                                                            | Passed | Failed | Blocked | Not tested | Notes                                                                                                                                                   |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ | ------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Server unit: business dates, phone normalisation, regex escaping, image signatures (new)                                                                                         | 7      | 0      | 0       | 0          |                                                                                                                                                         |
| Server API: content, settings, uploads, trainer cards, gallery, clean-up retry (new)                                                                                             | 9      | 0      | 0       | 0          | Uploads exercised with an in-memory **fake** media store; 503 path tested with the real unconfigured store                                              |
| Server API: plans (new)                                                                                                                                                          | 6      | 0      | 0       | 0          | Includes a partial-update regression test (D-73)                                                                                                        |
| Server API: inquiries (new)                                                                                                                                                      | 13     | 0      | 0       | 0          | Validation, normalisation, consent history, duplicate two-step, rate limit, CSRF, search/date filters, status, prefill, safeguarded delete, Trainer 403 |
| Server: Phase 1 suites incl. route-access matrix (now covering every Phase 2 route)                                                                                              | 46     | 0      | 0       | 0          |                                                                                                                                                         |
| **Server total**                                                                                                                                                                 | **81** | 0      | 0       | 0          |                                                                                                                                                         |
| Client unit (8 Phase 1 + 8 new: formatting, bilingual fallback, phone check, reordering, Phase 2 navigation)                                                                     | 16     | 0      | 0       | 0          |                                                                                                                                                         |
| E2E flow: Phase 1 (4) + Phase 2 (6): plans, gym details/content/trainer card, public site, Join form with repeat-number warning, inquiry review/status/delete, Trainer exclusion | 10     | 0      | 0       | 0          | Built client + real API + MongoDB 8.3 replica set                                                                                                       |
| Visual/responsive: 16 screens × 6 widths × 2 themes, dialogs at 360 px, 10 screens in Urdu RTL                                                                                   | 14     | 0      | 0       | 0          | 208 screenshots; automatic overflow and tap-target checks; manual design review                                                                         |
| Lint / build / i18n parity                                                                                                                                                       | ✓      | —      | —       | —          |                                                                                                                                                         |
| Real Cloudinary upload, replace and delete                                                                                                                                       | —      | —      | —       | ✓          | **P-05 pending.** Only the fake store and the 503 behaviour are tested                                                                                  |
| Real phones (iOS Safari, Android Chrome), WebKit                                                                                                                                 | —      | —      | —       | ✓          | Chrome device-width emulation only                                                                                                                      |

Acceptance scenarios touched in Phase 2: **AC-01** (inquiry saved, Admin-only, Trainer gets 403) **Passed** · **AC-02** (duplicate warning, submission still allowed, nothing private exposed) **Passed** · **AC-03** (conversion prefill with consent carried over) **Passed for the prefill only**; member creation is Phase 3 · **AC-04** (deleting an inquiry does not affect a converted member) **Partly**: deletion is independent and keeps consent history; the converted-member part can only be tested in Phase 3 · **AC-08** (Admin creates plans; Trainer gets 403) **Passed for plans**; custom price is Phase 4 · **AC-23** (safeguards and no cascade) **Passed** for inquiries, gallery images and trainer cards.

## 10. Phase 3 test report (17 Nov 2026)

| Suite                                                                                                                                                                                                                                                                                                                                                 | Passed  | Failed | Blocked | Not tested | Notes                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------ | ------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Server API: members (new)                                                                                                                                                                                                                                                                                                                             | 36      | 0      | 0       | 0          | Registration by both roles; Admin-only notes; duplicate phone (any formatting); validation; **25 concurrent registrations → GYM-001…GYM-025 with no duplicates or gaps**; 6 concurrent same-phone registrations → exactly one succeeds; conversion via prefill (Approved, `inquiry_conversion` consent, original consent time kept, no inquiry data on the profile); Trainer conversion 403; **2 concurrent conversions → one succeeds**; inquiry deletion leaves the member; live `matchesExistingMember`; search by name/phone/Member ID, state, date, sort, pagination, counts; edit with field-name-only logs; archive/restore by Trainer and Admin; archive block with an active membership; archived read-only; photos (503 unconfigured, upload/replace, clean-up after commit, failed clean-up queued, Admin-only safeguarded removal); opt-out/consent with immutable history; deletion Admin-only, dependency list, `DEPENDENCIES_EXIST` with nothing touched, deletion path when no linked record exists (simulated by clearing the test DB) |
| Server unit: Member ID format, `API_RATE_LIMIT` setting (new)                                                                                                                                                                                                                                                                                         | 2       | 0      | 0       | 0          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Server: Phase 1–2 suites incl. the route-access matrix (now covering every member route for anonymous, Trainer and Admin)                                                                                                                                                                                                                             | 81      | 0      | 0       | 0          | One Phase 2 assertion updated: the `members` collection now exists, so "no member created" checks the document count                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| **Server total**                                                                                                                                                                                                                                                                                                                                      | **119** | 0      | 0       | 0          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Client unit (16 earlier + 6 new: member navigation by role, business-date format, member form schema, Add Member screen for Trainer and Admin-from-inquiry, duplicate-phone field error)                                                                                                                                                              | 22      | 0      | 0       | 0          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| E2E flow: Phase 1 (4) + Phase 2 (6) + Phase 3 (6): Admin converts an inquiry; Trainer registers (duplicate blocked); search by name/phone/ID and sort; Trainer edits, archives, restores; Admin opt-out/consent and blocked deletion (UI and API); Trainer refused on every Admin-only member action (with the allowed Origin, asserting `FORBIDDEN`) | 16      | 0      | 0       | 0          | Built client + real API + MongoDB 8.3 replica set                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Visual/responsive: 24 screens × 6 widths × 2 themes, dialogs and member dialogs at 360 px, 14 screens in Urdu RTL                                                                                                                                                                                                                                     | 14      | 0      | 0       | 0          | Automatic overflow and tap-target checks; manual design review of the screenshots                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Lint / build / i18n parity                                                                                                                                                                                                                                                                                                                            | ✓       | —      | —       | —          | No type checker: the project is JavaScript by requirement (C-34)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Real Cloudinary member photos                                                                                                                                                                                                                                                                                                                         | —       | —      | —       | ✓          | **P-05 pending.** Only the test-only fake store and the 503 behaviour are tested                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Archive block from a real Phase 4 activation                                                                                                                                                                                                                                                                                                          | —       | —      | —       | ✓          | Tested against a stored `memberships` record; re-test when Phase 4 exists (D-92)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Real phones (iOS Safari, Android Chrome), WebKit                                                                                                                                                                                                                                                                                                      | —       | —      | —       | ✓          | Chrome device-width emulation only                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

Acceptance scenarios touched in Phase 3: **AC-03** (conversion with prefill; consent carries over with its history) **Passed** · **AC-04** (deleting the inquiry does not affect the converted member) **Passed** · **AC-05** (Admin and Trainer add and edit; duplicate phone prevented) **Passed** · **AC-06** (unique IDs under concurrency **Passed**; photo upload/replace for both roles and Admin-only removal **Passed with the fake store only**, real Cloudinary untested) · **AC-07** (archive blocked while active, restore reuses record and ID, both roles) **Passed** (active membership simulated until Phase 4) · **AC-23** (safeguards, dependency check, no cascade) **Passed** for member photos and members.

Found and fixed during Phase 3 testing: two links below the 36 px tap target the check used at the time (raised to 44 px in Revision 2, §11) (member table name, converted-member link); the browser suite hitting the general API rate limit (D-93); an E2E 403 check that was passing because of the CSRF check rather than the permission check.

## 11. Phase 3 Revision 2 test report (18 Nov 2026)

The touch-target check in the visual suite now requires **44 × 44 px** (SRS §13, C-02). The Phase 1–3 reports above were produced with a 36 px check; every screen has now been re-checked at 44 px. Checkboxes and radios are measured by the label that wraps them; tabs and menu items are included.

**Counts per file (actual run on 18 Nov 2026).**

| File                                                                         | Tests   | Result                                                          |
| ---------------------------------------------------------------------------- | ------- | --------------------------------------------------------------- |
| server `tests/unit/policies.test.js`                                         | 16      | 16 passed                                                       |
| server `tests/unit/utils.test.js`                                            | 8       | 8 passed                                                        |
| server `tests/integration/auth.test.js`                                      | 16      | 16 passed                                                       |
| server `tests/integration/users.test.js`                                     | 11      | 11 passed                                                       |
| server `tests/integration/permissions.test.js`                               | 4       | 4 passed                                                        |
| server `tests/integration/content.test.js`                                   | 9       | 9 passed                                                        |
| server `tests/integration/plans.test.js`                                     | 6       | 6 passed                                                        |
| server `tests/integration/inquiries.test.js`                                 | 13      | 13 passed                                                       |
| server `tests/integration/members.test.js`                                   | 36      | 36 passed                                                       |
| **Server total**                                                             | **119** | **119 passed, 0 failed, 0 skipped**                             |
| client `tests/unit/foundation.test.jsx`                                      | 8       | 8 passed                                                        |
| client `tests/unit/phase2.test.js`                                           | 8       | 8 passed                                                        |
| client `tests/unit/phase3.test.jsx`                                          | 7       | 7 passed (1 added in Revision 2: pagination arrows are 44 × 44) |
| **Client unit total**                                                        | **23**  | **23 passed**                                                   |
| `tests/e2e/01-flow.spec.js`                                                  | 4       | 4 passed                                                        |
| `tests/e2e/03-phase2-flow.spec.js`                                           | 6       | 6 passed                                                        |
| `tests/e2e/04-phase3-flow.spec.js`                                           | 6       | 6 passed                                                        |
| `tests/e2e/09-visual.spec.js` (6 widths × 2 themes, dialogs at 360 px, Urdu) | 14      | 14 passed                                                       |
| **Playwright total**                                                         | **30**  | **30 passed**                                                   |

Lint: passed (no errors, no warnings). Production build: passed. i18n parity: passed.

**Reconciliation.** Phase 3 added 38 server tests: 36 in `members.test.js`, 1 Member ID format test in `utils.test.js` and 1 `API_RATE_LIMIT` test in `policies.test.js`. `PROJECT_STATUS.md` and `CHANGELOG.md` had said 37 and 118; the table in `PROJECT_STATUS.md` and §10 here already said 119. Both are corrected.

**First 44 px run.** Before the fixes, 14 of the 30 Playwright tests failed (every visual width, in both themes). The undersized controls were: small buttons ("Upload image", 36 px tall), segmented filter options (36 px; "All" also 41 px wide), the "Call" links, the dashboard "Edit profile" link, the collapsed logo link (36 px wide), public header links (36 px), pagination arrows and the dialog close button (40 px), and the on/off switches. After the fixes all 30 passed. Pagination arrows (40 px) were found by code review, not by the visual suite (no list there is long enough to paginate); they are fixed and covered by a client unit test.

**Not tested:** real phones and WebKit (Chrome device emulation only), real Cloudinary (P-05).

## 12. Phase 4 test report (18 Nov 2026)

**Counts per file (actual run).**

| File                                                                                                                | Tests   | Result                              |
| ------------------------------------------------------------------------------------------------------------------- | ------- | ----------------------------------- |
| server `tests/unit/memberships.test.js` (new)                                                                       | 25      | 25 passed                           |
| server `tests/integration/memberships.test.js` (new)                                                                | 23      | 23 passed                           |
| server: all Phase 1–3 files (as in §11)                                                                             | 119     | 119 passed                          |
| **Server total**                                                                                                    | **167** | **167 passed, 0 failed, 0 skipped** |
| client `tests/unit/phase4.test.jsx` (new)                                                                           | 7       | 7 passed                            |
| client: Phase 1–3 files (8 + 8 + 7)                                                                                 | 23      | 23 passed                           |
| **Client unit total**                                                                                               | **30**  | **30 passed**                       |
| `tests/e2e/05-phase4-flow.spec.js` (new)                                                                            | 6       | 6 passed                            |
| `tests/e2e/01`, `03`, `04` flows                                                                                    | 16      | 16 passed                           |
| `tests/e2e/09-visual.spec.js` (28 screens × 6 widths × 2 themes, 44 px targets, dialogs at 360 px, 16 Urdu screens) | 14      | 14 passed                           |
| **Playwright total**                                                                                                | **36**  | **36 passed**                       |

Lint: passed. Production build: passed. i18n parity: passed. The two concurrency-heavy files (`members`, `memberships`) were also run 5 times in a row: 59/59 each time.

**What the new tests cover.**

- **Unit:** monthly end dates (calendar months, inclusive, SRS example 1 Nov → 30 Nov), month-end and leap-year cases (31 Jan → 28/29 Feb, 29 Feb + 12 months → 28 Feb), custom days, renewal start days across month and year ends, day counts, the payment summary statuses (pending never counts as paid) and the overpayment guard.
- **API, by role:** Trainer and Admin create and activate; custom price is Admin-only, needs a reason and is logged with the old and new price; archived members, inactive plans and a zero price are refused; overpayment and future dates are blocked, backdating is allowed; activation with a partial verified payment makes the member Active; **zero verified payment blocks activation** (no payment, or a pending one only); activation later with the first payment; early renewal (Upcoming from the day after expiry) and late renewal (from the activation date, member reactivated); one Upcoming/Pending at a time, also with 5 concurrent requests; no client dates and no pause/cancel/plan-change routes; the lifecycle job (expire, promote, member Inactive/Active, system-actor logs), **idempotency**, catch-up after missed days, two overlapping runs, the non-re-entrant lease lock, reconcile on read; **concurrent archive and activation** (exactly one succeeds, 4 rounds, consistent state); double activation; archive blocked while active; upcoming expiries for 7/14/30 days with the renewal flag, **Trainer 403**; membership deletion Admin-only and blocked while the payment summary exists; the path when no payment record exists (simulated in the test database).
- **E2E:** Trainer adds and activates with a part payment; early renewal is Upcoming with the server's start date checked against the current end date; archive refused while active; Admin custom price, unchecked online payment stays Pending activation and cannot be activated (UI and API), then activation with a verified payment for the rest; expiries on the Admin dashboard and screen, absent for the Trainer (UI and API 403); deletion blocked; Trainer custom price and deletion refused by the server.

**Found and fixed during Phase 4 testing.**

- The job lease lock was re-entrant within one process (D-97).
- On the Add membership form the amount did not follow a custom price, so the form refused valid input. The amount now follows the price.
- After the dashboard intro text changed, a Phase 2 E2E check for the text "New inquiries" also matched the new intro (in that run: 34 passed, 1 failed, 1 not run). The check now matches the exact card label; the next full run passed 36/36.

**Not tested:** real phones and WebKit; real Cloudinary (P-05). The scheduler's cron trigger itself (node-cron firing at 00:05) is not exercised; the job function and the lease lock are.

## 13. Phase 4 Revision 1 test report (18 Nov 2026)

Two corrections from the Phase 4 review (D-102): **cash is always verified** (refused as pending by the API schema, the service and the model), and **a fully pending online payment no longer offers an impossible activation**.

| Suite                                            | Tests   | Result                              | Change                                                                                                                                                                                                                                                                                                                                           |
| ------------------------------------------------ | ------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| server `tests/integration/memberships.test.js`   | 28      | 28 passed                           | +5: cash + pending refused for Admin and for Trainer (nothing saved); cash verified and online verified/pending accepted for both roles; unknown method/status and a pending activation payment refused; the model refuses pending cash; full pending stays Pending Activation (both roles) while partial pending can be completed and activated |
| **Server total**                                 | **172** | **172 passed, 0 failed, 0 skipped** | +5                                                                                                                                                                                                                                                                                                                                               |
| client `tests/unit/phase4.test.jsx`              | 9       | 9 passed                            | +2: no Activate button and an explanation when the full price is pending; the partial-pending workflow still activates with the remaining amount                                                                                                                                                                                                 |
| **Client unit total**                            | **32**  | **32 passed**                       | +2                                                                                                                                                                                                                                                                                                                                               |
| `tests/e2e/05-phase4-flow.spec.js`               | 7       | 7 passed                            | +1: cash + pending refused by the API for Admin and Trainer; a full unchecked online payment leaves the membership Pending Activation with the explanation and no Activate button                                                                                                                                                                |
| **Playwright total** (23 E2E + 14 visual, 44 px) | **37**  | **37 passed**                       | +1                                                                                                                                                                                                                                                                                                                                               |

Lint: passed. Production build: passed. i18n parity: passed.
One existing Phase 4 server test used cash + pending as its "pending payment" example; it failed once the rule was enforced, which is the intended change. Its data now uses an online pending payment.

## 14. Phase 5 test report (18 Nov 2026)

Payments and receipts (D-103 to D-108). Every number below comes from an actual run on 18 Nov 2026 (server suite run 3 times in a row with the same result).

| Suite                                       | Tests   | Result                              | Change                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------------------------------------- | ------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| server `tests/integration/payments.test.js` | 18      | 18 passed                           | new: one receipt per verified payment with a frozen snapshot; pending money never counts and gets no receipt; pending cash, future dates and archived members refused (both roles), backdating allowed; stale version and duplicate submissions (exactly one succeeds); old balance stays on its own summary after renewal; Trainer verify (receipt issued); Admin reject with reason; two simultaneous Verify → one valid receipt; full pending → verify → activate; correction with reason voids and reissues the receipt and keeps history; invalid corrections refused; Admin-only total-due correction never below paid + pending; ledger and deletions Admin-only, both roles read member payments and receipts; ledger filters; real PDF for both roles including VOID; idempotent receipt backfill (skips pending and deleted); deletion order receipts → entries → summary unblocks the membership; correction history kept and counted as protected |
| server `tests/unit/memberships.test.js`     | 27      | 27 passed                           | +2: receipt numbers REC-0001 … past 9999; PDF renders (valid and VOID) with no network or file access                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| other server files                          | 147     | 147 passed                          | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| **Server total**                            | **192** | **192 passed, 0 failed, 0 skipped** | +20                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| client `tests/unit/phase5.test.jsx`         | 6       | 6 passed                            | new: ledger Admin-only; payment page shows Trainer actions without Admin-only ones; cash recorded as verified, unchecked online as pending, with the version; corrections send only changed fields and a reason; reload after a version conflict; nothing more to record while the rest is pending                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| other client files                          | 32      | 32 passed                           | `phase4.test.jsx` text matcher updated for the new "Open Payments to verify (or reject) it" wording                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| **Client unit total**                       | **38**  | **38 passed**                       | +6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `tests/e2e/06-phase5-flow.spec.js`          | 5       | 5 passed                            | new: Trainer verifies a fully pending payment then activates; Trainer rejects a pending payment, records the rest in cash, receipt is a PDF; Trainer correction voids the old receipt and shows history; Admin ledger filters, total-due correction and blocked deletion; duplicates and Admin-only actions enforced by the server                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| other E2E files (01–05)                     | 23      | 23 passed                           | `05-phase4-flow` matcher updated for the new wording                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| visual suite `09-visual.spec.js`            | 14      | 14 passed                           | +3 screens (payment as Admin, payment as Trainer, ledger), +2 Urdu screens, the 360 px dialog test now also opens the Correct payment dialog; 44 px targets                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| **Playwright total** (28 E2E + 14 visual)   | **42**  | **42 passed, 0 failed** (11.8 min)  | +5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

Lint: passed. Production build: passed. i18n parity: passed.

**Not run / not verified:** real phones and WebKit/Safari; any external payment provider (none is integrated: online payments are recorded and verified by staff by hand); real Cloudinary; SMTP; hosting; the cron trigger itself (the job function is tested with an injected clock). Receipt sharing over WhatsApp is Phase 7 and is not tested.

## 15. Phase 5 Revision 1 test report (18 Nov 2026)

Fixes: the receipt `snapshot` in API responses (D-109), receipt dates when a payment is taken at activation (D-109), and the supported Node.js versions (D-110). All numbers are from actual runs on 18 Nov 2026, on Node 22.23.4.

| Suite                                       | Tests   | Result                              | Change                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ------------------------------------------- | ------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| server `tests/integration/payments.test.js` | 22      | 22 passed                           | +4: every snapshot field (gymName, logoUrl, memberName, memberCode, planName, startDate, endDate, totalDue, eventAmount, cumulativePaid, balance, method, paymentDate, reference) checked by value from `GET /receipts/:id` and `GET /members/:memberId/receipts`, as Admin and as Trainer, for an online payment with a reference and a backdated cash payment, with no Mongoose internals; a corrected entry's VOID receipt keeps its original snapshot, `replacedBy` / `replacedByNumber` point to the new receipt and the new one's `replaces` points back, in both endpoints; receipt dates for a payment taken at activation, including an early renewal (Upcoming dates); a receipt issued before activation keeps empty dates and is not rewritten |
| server `tests/unit/memberships.test.js`     | 28      | 28 passed                           | +1: `snapshotView()` returns exactly the snapshot fields for hydrated and lean receipts                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| other server files                          | 147     | 147 passed                          | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| **Server total**                            | **197** | **197 passed, 0 failed, 0 skipped** | +5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| **Client unit total**                       | **38**  | **38 passed**                       | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| E2E flows (`01`, `03`–`06`)                 | 28      | 28 passed                           | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| visual suite `09-visual.spec.js`            | 14      | 14 passed                           | unchanged (44 px targets)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| **Playwright total**                        | **42**  | **42 passed, 0 failed** (12.4 min)  | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |

Lint: passed. Prettier check: passed. i18n parity: passed. Production build: passed.

**The tests were shown to catch the defects.** Against the previous `receiptView()`, both snapshot tests failed (the snapshot had 4 keys, the Mongoose internals, instead of 14 fields). With the snapshot fix but without the date fix, the "every field" and early-renewal tests failed on empty `startDate`/`endDate`. Both pass with the fixes.

**Node.js versions (D-110).** A script compared the declared range with every `engines.node` in `package-lock.json`: with `>=22`, 44 of 313 packages are not guaranteed a supported Node; with `^22.22.2 || ^24.15.0 || >=26.0.0`, none. `npm install` on Node 22.23.4 completes with no engine warnings. With `engine-strict`, a simulated Node 22.19.0 is refused (`EBADENGINE`, "Unsupported engine"). **Not run:** the suites on Node 24.x or 26.x (only Node 22.23.4 is installed here); a real install on an older Node (simulated by overriding `process.version`).

**Not run / not verified (unchanged):** real phones and WebKit/Safari; payment providers (none integrated); real Cloudinary; SMTP; hosting; the cron trigger itself.

## 16. Phase 6 test report (18 Nov 2026)

Trainer experience: exercise library, workout notes, Trainer dashboard, Trainer lifecycle re-verification (D-111 to D-115). Every number below is from actual runs on 18 Nov 2026 on Node 22.23.4.

| Suite                                          | Tests   | Result                                                                    | Change                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ---------------------------------------------- | ------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| server `tests/integration/phase6.test.js`      | 12      | 12 passed                                                                 | new. **Exercises:** Admin and Trainer add, list (sorted), search (escaped), edit with updated-by; duplicates refused in any letter case and spacing, for both roles, also on rename, while re-casing its own name is allowed; 5 simultaneous same-name additions → exactly one 201; validation; no delete route; anonymous 401. **Notes:** all staff add; per-viewer `canEdit`/`canDelete`; activity log never contains note text; Trainer B cannot edit or delete Trainer A's note (403 `NOT_NOTE_AUTHOR`, nothing changed); own edit with version, stale version 409; Admin edits and deletes any note, author unchanged; soft delete keeps the document, hidden from Trainers (list, `status=deleted | all`403, edit/delete 404), Admin filter and`deletedCount`, no second delete or edit (409 `NOTE_DELETED`), the model refuses `deleteOne`/`deleteMany`, notes block member deletion as protected records; archived member: read for both roles, create/edit/delete 409 `MEMBER_ARCHIVED` for both, works again after restore; text validation and unknown member. **Dashboard:** member counts, payment-status counts (paid, partial, pending, unpaid; archived member and expired memberships excluded; awaiting verification), no money in the response, 5 newest non-deleted notes with the member, only the Trainer's own actions, no expiries; Admin 403. **Lifecycle:** deactivation → open session 401 at once and the note shows the author as Deactivated; reactivation → login and own edit work; force logout → 401, login again works; dependencies list notes and payments as retained; deletion → 401, login refused, notes and payment entries keep the original name, nothing removed; Admin can still manage the former Trainer's note, another Trainer cannot |
| server `tests/unit/phase6.test.js`             | 6       | 6 passed                                                                  | new: exercise name cleaning and case-insensitive key (incl. Unicode NFC and Urdu), exercise validators; note permission flags for author, other Trainer, Admin and deleted notes; author view with account state; note validators; payment statuses                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| server `tests/integration/permissions.test.js` | 4       | 4 passed                                                                  | unchanged; the automated route-access test now also covers every Phase 6 route (anonymous 401, Trainer 403 where the route permission excludes Trainers)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| other server files                             | 193     | 193 passed                                                                | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| **Server total**                               | **215** | **215 passed, 0 failed, 0 skipped**                                       | +18                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| client `tests/unit/phase6.test.jsx`            | 9       | 9 passed                                                                  | new: Exercises in the nav for both roles and in the Trainer phone bar only; list, search and add with a duplicate name shown on the field; edit sends only changed fields, no delete; notes card shows only server-allowed actions, Former staff badge, no deleted filter for Trainers, trimmed add; archived read-only; Admin deleted filter and soft delete with the version; edit sends the version and reloads after a conflict; a slow earlier list response never replaces a newer one; Trainer dashboard counts, linked notes, translated and fallback activity, no money, no expiries                                                                                                           |
| other client files                             | 38      | 38 passed                                                                 | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| **Client unit total**                          | **47**  | **47 passed**                                                             | +9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `tests/e2e/07-phase6-flow.spec.js`             | 5       | 5 passed                                                                  | new: exercise library by Trainer and Admin (case-insensitive duplicate refused in the UI and API, search, edit, Trainer phone bottom bar); two Trainers and the Admin on notes (own edit and soft delete, other Trainer has no actions and the API refuses, Admin deleted filter and edit with the author kept); archived member read-only in the UI and API; Trainer dashboard (counts, linked notes, own 10 latest actions, no expiries, no amounts; Admin dashboard unchanged, Admin 403 on the Trainer endpoint); Trainer lifecycle (deactivate ends the open session, Deactivated label, reactivate, force logout, delete; notes keep the name with Former staff)                                  |
| other E2E files (01–06)                        | 28      | 28 passed                                                                 | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| visual suite `09-visual.spec.js`               | 14      | 14 passed                                                                 | +2 screens (Exercises as Admin and Trainer) at 6 widths × 2 themes; the deleted-notes filter, note edit and delete dialogs and the exercise dialog at 360 px; +2 Urdu screens (Exercises, Trainer dashboard); the member profile and Trainer dashboard screens now include the new cards; 44 px targets                                                                                                                                                                                                                                                                                                                                                                                                 |
| **Playwright total** (33 E2E + 14 visual)      | **47**  | **47 passed, 0 failed**, in two consecutive full runs (14.1 and 13.4 min) | +5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

Lint: passed. i18n parity: passed. Production build: passed.

**Found and fixed while testing Phase 6.** (1) The first full browser run served a client build made before the notes and dashboard cards got their accessible names, so 2 tests waited for the "Workout notes" region and timed out (42 passed, 2 failed, 3 not run). The client was rebuilt; the browser suite serves the existing build (`docs/SETUP.md` §5). (2) An E2E assertion expected "Added an exercise" among the Trainer's latest activity, but by then the Trainer had done more than 10 things; the dashboard correctly shows the 10 latest. The test now checks the 10-item limit and the newest actions (45 passed, 1 failed, 1 not run before the fix). (3) Design review of the screenshots: on the member profile at desktop width the Admin filter label "Deleted (1)" wrapped onto two lines; the labels now stay on one line (fixed, then the full suite was run again). (4) One full run failed in the notes flow: after a delete, the deleted note was still listed. The test clicked the _first_ note's menu, which depends on list order and timing, and the notes card applied list responses in arrival order, so a slower earlier reload could overwrite a newer list. Both were fixed: the test now picks the note by its text, and the card applies only the latest response (a client test proves it, and fails without the fix). The full suite was then run twice in a row. (5) Mutation checks: removing the note ownership rule made 2 of the new API tests fail; removing the latest-response guard made its client test fail.

**Not run / not verified:** real phones and WebKit/Safari; Node 24.x/26.x; Cloudinary; SMTP; hosting; WhatsApp (Phase 7).

## 17. Phase 7 test report (18 Nov 2026)

WhatsApp (D-116 to D-123). Every number below is from actual runs on 18 Nov 2026 on Node 22.23.4.

**What "tested" means here.** No test contacted Meta. Three kinds of provider were used, and they are named in every row:

- **Fake provider** (`tests/helpers/fakeWhatsApp.js`): scripted successes and errors, used by the server API tests.
- **Fake Graph server**: a local HTTP server that imitates the Graph API, used to test the real Cloud API adapter's requests and error handling.
- **Simulated mode** (`WHATSAPP_MODE=mock`): used by the browser tests; everything is labelled "Simulated".
  **Real WhatsApp delivery, real Meta template approval and real Meta webhooks were not tested** (P-06: no Meta account yet).

| Suite                                                       | Tests   | Result                                                        | What it covers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ----------------------------------------------------------- | ------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| server `tests/integration/whatsapp.test.js` (fake provider) | 29      | 29 passed                                                     | **Templates:** Admin-only management (Trainer 403 on create, edit, delete); Trainers see only sendable templates; validation (name, language, placeholder gaps, one value per placeholder, keys allowed per event, receipt template must attach the PDF, no default for manual, unknown fields); duplicate name 409; content edit → waiting for approval and re-submitted, on/off without re-submission, one default per event; Meta rejection and switched-off WhatsApp never reported as approved; safeguarded delete keeps message history. **Automatic events:** confirmation and payment received queued in the activation transaction with the exact text, sent by the dispatcher, never twice; payment received for verification but not for corrections; no consent, landline, and opt-out after queueing → recorded as not sent, provider never called; 5 simultaneous identical events → 1 message; 3 simultaneous dispatchers → each message sent once; **temporary failure: exactly 3 retries, 15 minutes apart, then Failed with follow-up (4 provider calls)**; permanent failure not retried; success on a retry; interrupted send never re-sent; expiry reminders at 10:00, once, skipped after an activated renewal; expired notice at 10:00 only without a renewal, and not sent once the member renewed. **Manual sends:** sent for a consenting member; refused (nothing recorded or sent) for no consent, opt-out, archived, landline, for Admin and Trainer; unapproved, non-manual and incomplete templates refused; switched off → 503; 4 simultaneous requests with one request ID → 1 message; Trainers see only their own messages, 404 for others; Admin sees all with the provider ID; filters; Admin-only follow-up; preview with blockers sends nothing; history cannot be deleted and protects the member from deletion. **Receipts:** PDF attached (`%PDF-`), manual fallback when no receipt template, never called delivered; opt-out and void receipts blocked. **Webhook:** verification token; unsigned or wrongly signed → 401; statuses applied once and never backwards; failure → Failed with follow-up; template review update; no secret → 503. **Configuration:** settings shown as present/absent, never their values; Trainers see only the mode; immediate send reports the real outcome |
| server `tests/unit/whatsapp.test.js`                        | 16      | 16 passed                                                     | Placeholders, value resolution and formatting; mobile-only recipients; block reasons; 10:00 scheduling; error classification (permanent vs temporary); constant-time signature check; Meta status mapping; configuration (mock default, disabled when deployed, **mock refused in production**, live requires every credential, nothing secret in the summary); simulated provider behaviour. **Cloud API adapter against the fake Graph server:** request path, Bearer token only in the header, exact template payload; receipt PDF uploaded as multipart media then attached as the document header; Meta 131026 permanent, 130429 temporary, 502 temporary, timeout temporary; template submission with example values and status read-back                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| other server files                                          | 215     | 215 passed                                                    | Phase 1–6; the Phase 6 dashboard test now also expects `myRecentNotifications`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| **Server total**                                            | **260** | **260 passed, 0 failed, 0 skipped**                           | +45                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| client `tests/unit/phase7.test.jsx`                         | 10      | 10 passed                                                     | Honest outcomes (never "delivered" unless reported; simulated never success); WhatsApp nav for both roles; Trainer history notice and Simulated badge; Admin follow-up filter and resolution; review status, rejection reason and configuration card; template editor maps placeholders; read-only list for Trainers; send dialog lists only approved manual templates and blocks on server blockers; the same request ID is reused when a failed send is retried; receipt manual fallback                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| other client files                                          | 47      | 47 passed                                                     | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| **Client unit total**                                       | **57**  | **57 passed**                                                 | +10                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `tests/e2e/08-phase7-flow.spec.js` (simulated mode)         | 5       | 5 passed                                                      | Admin sets up templates (status as reported, simulated rejection, duplicate name on the field); Trainer sends from a member profile, no send button and API 409 without consent, Trainer cannot manage templates; temporary (Will retry) and permanent (Failed) failures, Admin follow-up; receipts: manual fallback, then WhatsApp once a receipt template exists, automatic payment-received message queued; signed webhook only (401 unsigned), delivered status shown, Trainer dashboard "Messages you sent", Trainers see only their own                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| other E2E files (01–07)                                     | 33      | 33 passed                                                     | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| visual suite `09-visual.spec.js`                            | 14      | 14 passed                                                     | +4 screens (WhatsApp messages and templates, Admin and Trainer) at 6 widths × 2 themes; message details, template editor, send dialog and receipt share dialog at 360 px; +2 Urdu screens; 44 px targets                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| **Playwright total** (38 E2E + 14 visual)                   | **52**  | **52 passed, 0 failed** (15.6 min, final run after all fixes) | +5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

Lint: passed. i18n parity: passed. Production build: passed.

**Found and fixed while testing Phase 7.**

1. Simultaneous requests with the same request ID could each be answered as new: an upsert that _matches_ a record another request just inserted was not counted as a duplicate. Fixed (`upsertedCount`); covered by the 4-request test.
2. A simulated send showed a green success message although its text said it was not sent. Simulated results now show as information.
3. **Test environment (since Phase 1):** Playwright starts the API server before its global setup, and the setup then dropped the database, so the browser tests ran without the unique, partial and TTL indexes. The server suites always had them, and the real server builds them at start-up, so production was not affected. Found when a duplicate template name was not refused in the browser test. Fixed: a new `npm run sync-indexes -w server` script (also usable at deployment) runs after the database is dropped, and template creation now also checks the name in the service. The first run after the fix could not start because the previous run had left a duplicate template; the stale E2E database was dropped once.
4. A dashboard wiring edit had silently not been applied (the Trainer's sent messages were missing); found by the API test and fixed.
5. Visual review: the new "View all" link on the Trainer dashboard was 39–43 px wide at 360–390 px (under 44 px), and "Not sent" rows did not show why; both fixed. Two browser-test selectors matched more than one element and were made exact.
6. Mongoose 9 warned that the `new: true` option is deprecated; the Phase 6–7 code now uses `returnDocument: 'after'` (same behaviour).

**Not run / not verified:** real WhatsApp delivery, real Meta template review and real webhooks (P-06); media upload to Meta; real phones and WebKit/Safari; Node 24.x/26.x; Cloudinary; SMTP; hosting; the node-cron triggers themselves (the job functions are tested directly).

## 18. Phase 8 test report (20 Nov 2026)

Dashboards, reports and expenses (D-124 to D-130). Every number below is from actual runs on 20 Nov 2026 on Node 22.23.4. Financial figures are checked against amounts worked out by hand from the records each test creates, and the dashboard is checked against the reports. PDFs are checked by **reading their text** (`tests/helpers/pdfText.js`, pdfjs-dist), not just their header. WhatsApp still runs only against the fake provider and the simulated mode (P-06).

| Suite                                     | Tests   | Result                                           | What it covers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ----------------------------------------- | ------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| server `tests/integration/phase8.test.js` | 18      | 18 passed                                        | **Expenses:** Admin create/list/filter (dates, method, category, filtered total)/detail with history/edit; server validation of every field (empty and too long titles, unknown category and method, Rs 0, negative, decimal, string, above the limit, impossible and malformed dates, unknown fields, missing fields, **future date 422**, today and the maximum allowed); `expectedVersion` required; **two simultaneous edits: one 200, one 409, one history entry**; safeguarded delete (wrong password 422, short reason, no confirmation; deletion audit without the record's data; 404 afterwards); **Trainer 403 on all six expense routes, nothing changed**. **Admin dashboard:** zeros for a new gym; a seeded gym (paid, partial with a backdated online payment and a rejected one, pending online, no plan, expired, archived) gives exactly Total 5 / Active 2 / Inactive 3 / Expired 1 / Archived 1, today Rs 5,000, month Rs 8,000 (cash 6,000, online 2,000), per-day series, outstanding without the archived member, new members today, no profit/net field; upcoming expiries appear a week before; a new month resets the income; inquiries counted by the Karachi day boundary; recent corrections with before/after, reason and actor, and income follows the correction; **each role gets 403 on the other dashboard**, the Trainer dashboard still has no money or expiries. **Reports:** income totals equal the dashboard; Cash/Online filters; archived member in totals but not listed until requested; inclusive range ends, backdated entries on their payment date, pending and rejected money never counted; 13 validation cases (missing/reversed/impossible dates, leap day, bad method, unknown filter, 731 vs 732 days, bad category/archive/state); **summary keeps income and expenses separate with no net/profit/difference field, also in the PDF text**; deleted expense left out of later JSON and PDF reports; PDF headers (type, attachment name, no-store), period, filter, "Generated 20 Nov 2026, 12:00 (Asia/Karachi) by …", totals, names, empty-range text; each PDF download logged with its filters, previews not; 5,001 records → 422 `REPORT_TOO_LARGE`; member list without/with/only archived members and no addresses; **full export: wrong password 422 and nothing logged; correct password → PDF with addresses, logged with filter and count only, no personal data in the log**; **Trainer 403 on all nine report/export routes, nothing logged** |
| server `tests/unit/phase8.test.js`        | 8       | 8 passed                                         | Report filter validation (inclusive range, leap years, 730/731/732 days, defaults, unknown values); expense validation (whole rupees 1–10,000,000, title tidy-up, SRS categories and methods); report PDF stamp on every page (gym, period, Karachi time, user, "Page n of n", 150 rows over several pages) and the empty-table text; Phase 8 permission keys Admin-only                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| other server files                        | 260     | 260 passed                                       | Phases 1–7 unchanged (member registration now uses the injected business clock; no test needed changing)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| **Server total**                          | **286** | **286 passed, 0 failed, 0 skipped**              | +26                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| client `tests/unit/phase8.test.jsx`       | 12      | 12 passed                                        | Admin dashboard figures in PKR, archived note only when there are archived members, empty/error/retry states, no profit text, chart axis rounding; expense form validation like the server, list total and empty state, edit sends only changed fields with the version; report presets (incl. January → December) and range errors; summary shows two separate totals and no net figure, PDF link carries the filters; income preview sends Cash/Online and the archived option; no request for an invalid range; full export shows a wrong password; Expenses/Reports navigation for Admins only                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| other client files                        | 57      | 57 passed                                        | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| **Client unit total**                     | **69**  | **69 passed**                                    | +12                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `tests/e2e/08-phase8-flow.spec.js`        | 5       | 5 passed                                         | Admin dashboard tiles equal `GET /dashboard/admin`, chart and table view, Trainers and corrections, no "profit"; expenses: form validation, add three, method filter and total, edit and history (Rs 45,000 → Rs 46,000), delete with a wrong then right password; reports: income preview equals the API, Cash filter, **real PDF download** (`%PDF-`, file name), reversed range explained without a request, summary with separate income/expenses and no net text, summary PDF, expenses by category; members: archived only on request, list PDF, full export wrong password then a real PDF download; Trainer: no Expenses/Reports links or money, `/app/expenses` and `/app/reports` redirect, API 403 on dashboard, expenses, reports, PDFs and export                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| other E2E files (01–07, 08-phase7)        | 38      | 38 passed                                        | Two assertions about the replaced interim Admin dashboard were updated: Phase 2 now finds new inquiries in the "Today" card; Phase 6 now checks that the Admin gets the Admin dashboard (Money) and not the Trainer's sections                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| visual suite `09-visual.spec.js`          | 14      | 14 passed                                        | +5 screens (Expenses; Reports: income, expenses, summary, members) at 360/375/390/414/768/1280 px × light/dark with overflow and 44 px checks; new Admin dashboard (existing screen); expense add dialog, action menu, history dialog and full-export dialog at 360 px in both themes; +4 Urdu RTL screens                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| **Playwright total** (43 E2E + 14 visual) | **57**  | **57 passed, 0 failed** (16.8 min, one full run) | +5 E2E                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| lint · i18n parity · production build     | —       | passed                                           | `npm run lint`, `npm run i18n:check -w client`, `npm run build`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

**Not tested:** real WhatsApp/Meta (P-06), Cloudinary (P-05), SMTP (P-07), hosting (P-02/P-03), real phones and WebKit/Safari, Node 24/26. Report PDFs were checked by text extraction and by download in Chrome, not printed.

## 19. Phase 9 test report (20 Nov 2026)

Settings & operational security (X-21 resolved by D-131; D-132 to D-135). Every number below is from actual runs on 20 Nov 2026 on Node 22.23.4. Backups ran against a **local folder** and the S3 adapter against a **local fake S3 server**; no real storage bucket was used (P-08). WhatsApp still runs only against the fake provider and the simulated mode (P-06).

| Suite                                     | Tests   | Result                                           | What it covers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ----------------------------------------- | ------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| server `tests/integration/phase9.test.js` | 19      | 19 passed                                        | **X-21:** a member with consent history: dependencies say `protectedHistory`/`archive`, deletion 409 `DEPENDENCIES_EXIST`, member, consent history, deletion audit and activity log unchanged, still blocked after archiving, Trainer 403; **every protected model refuses `deleteMany`, `deleteOne`, `findOneAndDelete` and document deletes** (consent, notifications, notes, corrections, activity log, login history, deletion audit); **the exact list of all 13 deletion routes is pinned**, none touches protected history, and the only "restore" route is the member archive-restore. **Settings:** saved settings survive an app restart and are logged; 5 invalid updates refused; Trainer 403 and nothing changed; the read-only security and retention rules exactly as approved; the 2-year TTL indexes exist and the deletion audit has none. **Audit viewers:** newest first, actor/action/record-type/date filters on the Karachi day, paging, filter values; personal values never in the log; 7 invalid queries 400; login history with a masked unknown identifier and a device summary, result and account filters, no IP hash; **Trainer 403 on all six routes, anonymous 401**. **Backups:** not configured → status and dashboard warning, nothing written; an encrypted file (no member names or password hashes in the bytes), checksum, sessions/reset tokens/job locks excluded; **restore into an empty database reproduces documents byte-for-byte (EJSON) and the same indexes**, records the restore, refuses a second restore into the now non-empty database, source untouched; refusals for a wrong confirmation, wrong key, a changed byte, wrong checksum and a non-backup file, with nothing written; **10 weekly runs keep exactly the newest 8**, a failed run keeps all 8, warns and has its error scrubbed, the next success clears it, 9 days later "stale"; two concurrent runs → one; files never overwritten and names checked. **Security:** `no-store` on API responses (also 404s), public site 60 s, no `x-powered-by`, `nosniff`; no password hashes, tokens, IP hashes or the backup key in nine Admin responses; **account lifecycle**: force logout ends two devices, deactivation ends the session and refuses sign-in with a generic message (history says "deactivated"), reset ends sessions and the old password, Trainer cannot change own password or manage accounts, deleting the account ends access, tombstones it and keeps its history attributable; bracket query keys cannot build operators |
| server `tests/unit/phase9.test.js`        | 9       | 9 passed                                         | Backup configuration (off by default; 32-byte key required; S3 needs region, bucket and both keys; local folder refused in production; a valid S3 production config accepted); file format round-trip, random IV, a changed header/IV/tag/body byte or wrong key detected; Karachi file names; **S3 adapter against a local fake S3 server** (prefix, SigV4 signature without the secret, get, no overwrite, remove, name check); identifier masking and device summaries; log redaction of backup secrets and passwords; generic 500 without internals; Phase 9 permissions Admin-only                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| other server files                        | 286     | 286 passed                                       | Phases 1–8 unchanged. `tests/helpers/pdfText.js` adjusted for pdfjs-dist 6 (D-134)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| **Server total**                          | **314** | **314 passed, 0 failed, 0 skipped**              | +28                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| client `tests/unit/phase9.test.jsx`       | 9       | 9 passed                                         | Settings overview (rules read-only, links to Website → Gym and WhatsApp → Templates, the archive explanation, no inputs), error and retry; Activity Log (labels, unknown action shown as its code, changed fields, reason, actor and record-type filters sent to the server, reversed range explained without such a request); Login history (unknown account, masked name, reasons, result filter); Backups (status, runs, failed run, operator-only restore note and **no restore control**), warnings (not set up, failed, stale, none), sizes; Settings in the navigation for Admins only                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| other client files                        | 69      | 69 passed                                        | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| **Client unit total**                     | **78**  | **78 passed**                                    | +9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `tests/e2e/08-phase9-flow.spec.js`        | 5       | 5 passed                                         | Settings overview and the Website link; Activity Log equals the API, Trainer filter, reversed range explained; Login history with a masked failed sign-in and the result filter; **the real `backup.js` script** writes an encrypted file, Settings shows it ("1 of 8") and the dashboard warning goes away; **restore drill with the real `restore.js`**: wrong confirmation refused, restore into a new database with the member count equal to the API, second restore refused (not empty), drill database dropped; member deletion dialog explains protected history and offers no delete, API 409, member still there; Trainer: no Settings link, no backup text, `/app/settings` redirects, 403 + `no-store` on all six routes                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| other E2E files (01–08-phase8)            | 43      | 43 passed                                        | unchanged; the Admin dashboard now also shows the backup warning                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| visual suite `09-visual.spec.js`          | 14      | 14 passed                                        | +4 screens (Settings: overview, Activity Log, Login history, Backups) at 360/375/390/414/768/1280 px × light/dark with overflow and 44 px checks; the blocked member-deletion dialog with the new explanation at 360 px (existing step); +3 Urdu RTL screens                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| **Playwright total** (48 E2E + 14 visual) | **62**  | **62 passed, 0 failed** (18.7 min, one full run) | +5 E2E                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| lint · i18n parity · production build     | —       | passed                                           | `npm run lint`, `npm run i18n:check -w client` (132 new keys each), `npm run build`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `npm audit`                               | —       | 0 vulnerabilities                                | After upgrading the test-only `pdfjs-dist` to 6.x (one high advisory before; production dependencies had none)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

**First runs (fixed before the final run):** the server tests had three mistakes of their own (no activity entry yet in a fresh database, two sign-ins read in the wrong order, and an expectation that a bracket query key would be refused, when Express 5 simply keeps it as text and the list ignores it; the test now checks that). The identifier masking expectation was corrected for lowercased sign-in names. One E2E selector ("To") matched two labels. The E2E MongoDB had stopped once and was restarted.

**Documentation fix:** the Phase 8 "Playwright total" row had been inserted into the Phase 5 table (§14) by mistake; it is now in §18.

**Not tested:** a real backup bucket (P-08), real WhatsApp/Meta (P-06), Cloudinary (P-05), SMTP (P-07), hosting (P-02/P-03), real phones and WebKit/Safari, Node 24/26.

## 20. Phase 9 Revision 1 test report (20 Nov 2026) — restore failure recovery

All numbers are from actual runs on 20 Nov 2026 on Node 22.23.4 (D-136). Restores ran against real MongoDB databases on the test replica set; failures were simulated through the restore's progress callback (as if the connection dropped after a batch) and by editing the marker as a crashed process would leave it. No real storage bucket was used (P-08).

| Suite                                             | Tests   | Result                                           | What it covers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ------------------------------------------------- | ------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| server `tests/unit/phase9-restore.test.js`        | 16      | 16 passed                                        | A valid backup parses; refused **before any write**: unknown format or app, missing time, bad or system collection name, `sessions` or `restoreState` inside a backup, negative count, wrong total, missing index list, indexes of an unknown collection, index without key, the `_id` index; duplicate `_id`, document without `_id`, unreadable line, unknown collection, missing documents, not gzip, unreadable manifest; `INVALID_BACKUP` / `CHECKSUM_MISMATCH` codes, wrong key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| server `tests/integration/phase9-restore.test.js` | 9       | 9 passed                                         | **Failure after 6 documents** → `PARTIAL_RESTORE` with both recovery routes, marker `failed`; **the server (`src/server.js`) and `sync-indexes.js` refuse the database and write nothing**; a fresh restore → `TARGET_PARTIAL`; **resume → an exact copy of the source** (EJSON with number types, indexes, one restore record, marker complete); resume again → `ALREADY_COMPLETE`. **Several failures in a row, also inside a collection** → resumes to an exact copy. **Resume refused, nothing written** over a changed document, an extra document, an unknown collection, or with a different backup file. **Lease:** a crashed run's marker blocks a resume until it expires, then resume completes; **two simultaneous fresh restores** → exactly one runs. **Wrong confirmation** (none, empty, other name, wrong case) on fresh and resume → nothing written. **Non-empty database without a marker** → refused for fresh and resume, untouched; **resume into an empty database** → refused, nothing created. **Successful one-go restore** with checksum; a backup of the restored database leaves the marker out. **CLI:** `--check` reports `partial_restore` and writes nothing; a fresh run prints `[TARGET_PARTIAL]` with `--resume`; `--resume --sha256` completes |
| other server files                                | 314     | 314 passed                                       | Phases 1–9 unchanged (the Phase 9 backup/restore tests pass against the reworked restore)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| **Server total**                                  | **339** | **339 passed, 0 failed, 0 skipped**              | +25                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| **Client unit total**                             | **78**  | **78 passed**                                    | unchanged (no client change)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `tests/e2e/08-phase9-flow.spec.js`                | 5       | 5 passed                                         | The restore drill now runs `restore.js --check` (valid, target empty) before the real restore                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| other E2E files                                   | 43      | 43 passed                                        | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| visual suite `09-visual.spec.js`                  | 14      | 14 passed                                        | unchanged                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| **Playwright total** (48 E2E + 14 visual)         | **62**  | **62 passed, 0 failed** (19.4 min, one full run) |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| lint · i18n parity · production build             | —       | passed                                           | `npm run lint`, `npm run i18n:check -w client`, `npm run build`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

**Found by the new tests and fixed:** (1) backups read documents with number promotion, so a double such as `5.0` came back as the integer `5` (money is whole rupees, so amounts were not affected); (2) restores did not recreate empty collections; (3) Mongoose `autoCreate` created empty collections on connect, before the start-up guard could refuse a partial database. First-run test mistake: the expected partial count was 5, but the failure hook runs after the 6th document is written.

**Not tested:** a real backup bucket (P-08) and restores of production-sized data; real WhatsApp (P-06), Cloudinary, SMTP, hosting, real phones and Safari.

## 21. Phase 10 final QA report (20 Nov 2026)

All numbers are from actual runs on 20 Nov 2026 on Node 22.23.4 with a local MongoDB 8.3 replica set and Chrome 153. Nothing was run against real hosting or external services (none exist yet).

### 21.1 Automated suites (final runs)

| Suite                                     | Tests  | Result                                           | Notes                                                                                                                                                                                                                                            |
| ----------------------------------------- | ------ | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Server unit + API (`npm run test:server`) | 339    | **339 passed, 0 failed, 0 skipped**              | Phases 1–9 incl. Revision 1; covers AC-01 – AC-26                                                                                                                                                                                                |
| Client unit (`npm run test:client`)       | 78     | **78 passed**                                    |                                                                                                                                                                                                                                                  |
| E2E flows `01`–`08`                       | 48     | **48 passed**                                    | Full workflows per phase for Admin, Trainer and visitors                                                                                                                                                                                         |
| Visual/responsive `09-visual`             | 14     | **14 passed**                                    | 46 screens × 6 widths × light/dark, dialogs at 360 px, Urdu RTL; overflow and 44 px targets                                                                                                                                                      |
| **Final QA `10-final-qa`**                | 5      | **5 passed**                                     | Cross-phase journey; production CSP; axe-core WCAG 2 A/AA in light, dark and Urdu                                                                                                                                                                |
| **Playwright total** (53 E2E + 14 visual) | **67** | **67 passed, 0 failed** (20.4 min, one full run) |                                                                                                                                                                                                                                                  |
| Lint (`npm run lint`)                     | —      | passed                                           | ESLint over server, client and tests                                                                                                                                                                                                             |
| Type check                                | —      | **not applicable**                               | The project is JavaScript by decision (Master Prompt §4, C-34); there is no TypeScript or JSDoc type configuration. Runtime validation (Zod), ESLint and `node --check` on every server file were run instead                                    |
| i18n parity                               | —      | passed                                           | English and Urdu have the same keys and placeholders                                                                                                                                                                                             |
| Client production build (`npm run build`) | —      | passed                                           |                                                                                                                                                                                                                                                  |
| Server production "build"                 | —      | passed                                           | The server has no build step; verified instead by a **clean production-only install** (`npm ci --omit=dev -w server --include-workspace-root=false`, no dev package present) that started in `NODE_ENV=production` and answered the health check |
| `npm audit`                               | —      | 0 vulnerabilities                                |                                                                                                                                                                                                                                                  |

### 21.2 Final QA checks added (`client/tests/e2e/10-final-qa.spec.js`)

- **Cross-phase journey:** a visitor's Join Now inquiry (Trainer 403 on inquiries) → Admin conversion with prefill → Monthly membership with a partial verified cash payment and activation → member Active → Trainer records the rest as a pending online payment (balance unchanged) and verifies it (paid, two receipts) → Trainer workout note; Trainer refused the ledger, reports, expenses, audit, settings, Admin dashboard and member deletion → Admin correction of the cash entry (old receipt void, new one issued, correction logged) → dashboard collections, the income report and the Activity Log all agree → archive refused while active; deleting the inquiry leaves the member and payments intact → the member and payment pages show the same in the browser.
- **Production CSP:** the headers from `client/vercel.json` are applied to every response of the built app; 10 screens across visitor, Admin and Trainer load with **no CSP violations**.
- **Accessibility:** axe-core with WCAG 2 A/AA rules on 13 screens (public home, Join, sign-in, Admin dashboard, members, payments, expenses, reports, WhatsApp, settings, staff, Trainer dashboard, exercises) in light and dark, and 4 screens in Urdu (with `dir="rtl"` and `lang="ur"` checked): **no serious or critical issues**. Moderate/minor axe findings are not gated.

### 21.3 Production-mode start (manual, scripted with curl)

Run against a throw-away local database with `NODE_ENV=production`:

- Refused to start without SMTP and `TRUST_PROXY`, with `WHATSAPP_MODE=mock`, with `BACKUP_STORAGE=filesystem`, and with `WHATSAPP_MODE=live` but no credentials — each with a clear list of problems.
- Health check `200 {"status":"ok","db":"up"}`; headers HSTS, `nosniff`, `X-Frame-Options`, `Referrer-Policy`, COOP/CORP, `Cache-Control: no-store`, no `x-powered-by`.
- First-Admin setup with the token (a password containing the username was correctly refused first); setup closed afterwards; sign-in cookie `HttpOnly; Secure; SameSite=Lax; Max-Age=7776000`.
- Foreign-origin POST → 403 `ORIGIN_REJECTED`; foreign CORS preflight → no `Access-Control-Allow-Origin`; allowed origin → origin echoed with credentials; malformed JSON → 400; `text/plain` → 415; unknown route → 404; unsigned webhook without WhatsApp configured → 503; WhatsApp status `disabled`; backup status `not_configured`.

### 21.4 Regression (approved rules re-confirmed by the suites above)

Membership expiry and renewal (early → Upcoming, late → activation date), Monthly vs custom-day dates and month-end fallback, status transitions, partial and pending online payments, cash always verified, receipts and void/reissue corrections, archive/restore (both roles), inquiry conversion and independent deletion, Trainer permissions, workout-note ownership and soft delete, WhatsApp consent/opt-out, 3 retries and idempotency, report filters with income and expenses separate, expense history, X-21 protections, settings persistence, backup and restore recovery — all covered by passing tests listed in §11 – §20 and re-run here.

### 21.5 Bugs found in Phase 10 and fixed

| #   | Finding                                                                                                                         | Fix                                                           |
| --- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| 1   | Status badges and coloured text below WCAG AA contrast (light amber 2.7:1, green 4.2:1, red 4.1:1; dark blue on its tint 4.2:1) | Tokens adjusted within the same hues (D-137); axe passes      |
| 2   | Zod 4 `new Function` probe reported a CSP violation on every page with a form under the production policy                       | `z.config({ jitless: true })` (`client/src/lib/zodConfig.js`) |
| 3   | `docs/DEPLOYMENT.md` told Render to run a non-existent `npm run build -w server`, and described index creation wrongly          | Rewritten; production install verified                        |
| 4   | No guidance for client IPs behind Vercel + Render (`TRUST_PROXY`)                                                               | Documented (2 expected) with a staging check                  |
| 5   | `npm run backup`/`restore` did not read `server/.env`                                                                           | `--env-file-if-exists=.env` like the other scripts            |
| 6   | Phase 6 browser test could match two "Note added" toasts                                                                        | Uses the newest toast                                         |
| 7   | `.mongo-data/` (local MongoDB folder from SETUP) not git-ignored                                                                | Added to `.gitignore`                                         |

First-run test mistakes in the new spec (not product bugs): an invalid `status=all` filter, reading the user ID from the wrong field, expecting 2 instead of 3 receipt links (the voided one stays visible), theme/language storage keys, and the staff accounts' saved Urdu language left by the visual suite (now reset before the spec).

### 21.6 Not tested (needs real accounts or devices)

Real hosting (Render, Vercel, Atlas), HTTPS/HSTS as served there, `TRUST_PROXY` with the real proxy chain, SMTP email, Cloudinary uploads, Meta WhatsApp delivery/templates/webhooks, a real backup bucket and restores of production-sized data, real phones (Android, iPhone Safari/WebKit), Node 24/26, and a native-speaker Urdu review.
