fix(GRO-2105): include serviceId in BookingFlow/RescheduleFlow availability call #46

Merged
Flea Flicker merged 1 commits from flea/gro-2105-booking-availability-fix into dev 2026-06-02 19:06:15 +00:00
Member

Summary

Both portal flows (BookingFlow and RescheduleFlow in src/portal/sections/Appointments.tsx) were calling GET /api/book/availability with only the date query param. The API responded 400 {error:"serviceId and date are required"} and the React handler called .map() on that error object, throwing TypeError: ee.map is not a function and wiping <div id="root">. The entire page went blank.

This restores the test cases blocked by GRO-2105 — TC-WEB-5.12.5 through 5.12.11 in UAT_PLAYBOOK.md §5.12b.

Changes

  • New helper fetchAvailability({serviceId, date}, sessionId) in Appointments.tsx that:
    • Validates res.ok (returns the API's error string on 4xx/5xx instead of letting .map() crash)
    • Validates the body is actually an array (defends against future 200-but-object responses)
    • Catches network errors and returns a uniform Failed to load time slots message
  • RescheduleFlow: passes appt.serviceId (the appointment's existing service).
  • BookingFlow: passes selectedServices[0]?.id (matches the same serviceId already used when the booking is submitted).
  • Cancellation guard via a cancelled flag prevents stale responses from overwriting state when the date changes mid-flight.

Tests

  • Updated the existing test that asserted the buggy URL (/api/book/availability?date=…) to expect the correct URL with serviceId.
  • Added two regression tests for RescheduleFlow: one for 4xx with a {error} body, and one for a 200 with a non-array body. Both assert the error message is shown and the page does not crash.

Verification

  • pnpm test → 141 / 141 pass
  • pnpm run typecheck → clean
  • pnpm run lint → 0 errors (3 pre-existing warnings, unrelated)
  • pnpm run build → clean, bundle includes serviceId and the error-path strings

UAT Playbook

Updated UAT_PLAYBOOK.md §5.12b to clarify that the call must include serviceId and that the error state must keep the page interactive (no white screen).

## Summary Both portal flows (`BookingFlow` and `RescheduleFlow` in `src/portal/sections/Appointments.tsx`) were calling `GET /api/book/availability` with only the `date` query param. The API responded `400 {error:"serviceId and date are required"}` and the React handler called `.map()` on that error object, throwing `TypeError: ee.map is not a function` and wiping `<div id="root">`. The entire page went blank. This restores the test cases blocked by GRO-2105 — TC-WEB-5.12.5 through 5.12.11 in `UAT_PLAYBOOK.md` §5.12b. ## Changes - **New helper** `fetchAvailability({serviceId, date}, sessionId)` in `Appointments.tsx` that: - Validates `res.ok` (returns the API's `error` string on 4xx/5xx instead of letting `.map()` crash) - Validates the body is actually an array (defends against future 200-but-object responses) - Catches network errors and returns a uniform `Failed to load time slots` message - **RescheduleFlow**: passes `appt.serviceId` (the appointment's existing service). - **BookingFlow**: passes `selectedServices[0]?.id` (matches the same `serviceId` already used when the booking is submitted). - **Cancellation guard** via a `cancelled` flag prevents stale responses from overwriting state when the date changes mid-flight. ## Tests - Updated the existing test that asserted the buggy URL (`/api/book/availability?date=…`) to expect the correct URL with `serviceId`. - Added two regression tests for RescheduleFlow: one for `4xx` with a `{error}` body, and one for a `200` with a non-array body. Both assert the error message is shown and the page does not crash. ## Verification - `pnpm test` → 141 / 141 pass - `pnpm run typecheck` → clean - `pnpm run lint` → 0 errors (3 pre-existing warnings, unrelated) - `pnpm run build` → clean, bundle includes `serviceId` and the error-path strings ## UAT Playbook Updated `UAT_PLAYBOOK.md` §5.12b to clarify that the call must include `serviceId` and that the error state must keep the page interactive (no white screen).
Flea Flicker added 1 commit 2026-06-02 19:04:00 +00:00
docs(GRO-2105): clarify §5.12 test cases require serviceId + non-array error path
CI / Test (pull_request) Successful in 21s
CI / Lint & Typecheck (pull_request) Successful in 26s
CI / Build & Push Docker Image (pull_request) Successful in 54s
e4252d88d4
Flea Flicker merged commit f0c58c193c into dev 2026-06-02 19:06:15 +00:00
Sign in to join this conversation.