Phase 4
Seed data extended with a second barber (different hours/services), a beard-trim service + category, breaks, time off, a guest customer, and appointments in all three key states — verified against a live throwaway Postgres. 14 new integration tests (38 total with Phase 3's) covering guest/authenticated booking, any-barber assignment, slot-conflict handling, ownership enforcement, guest-data isolation, and book-again repricing. Playwright E2E suite for the 6 required customer journeys, with its own global-setup.ts that migrates and seeds a database automatically. Full verification pass, which caught and fixed three real bugs along the way (not just test-workarounds): A date off-by-one bug in the calendar picker that made real weekdays show as closed for anyone in a UTC+ timezone (including the business's own). A dialog that could vanish mid-confirmation on cancellation, before the customer could read the late-cancellation notice. A silent test-cleanup leak in the Phase 3 fixtures that had been leaking stray businesses since Phase 3. Plus a baseline desktop-responsive fix (centered max-w-2xl columns) across Home/Appointments/Settings/booking flow, since desktop had been effectively unstyled. Final state: 90 unit tests, 38 integration tests, and all 6 E2E journeys passing together on a fresh database; clean tsc, eslint, and next build. Full writeup with routes, security model, guest-matching rules, known limitations, and what to check before Phase 5 is in docs/phase-4-summary.md.
This commit is contained in:
66 files changed
+4599
-107
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { BOOKING_VALIDATION_ERROR_CODES } from "@/services/scheduling/types";
|
||||
import { getFirstFriendlyMessage, getFriendlyMessage, getFriendlyValidationMessages } from "../error-messages";
|
||||
|
||||
describe("getFriendlyMessage", () => {
|
||||
it("has a specific, non-empty message for every code the domain layer can produce", () => {
|
||||
for (const code of BOOKING_VALIDATION_ERROR_CODES) {
|
||||
const message = getFriendlyMessage(code);
|
||||
expect(message.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it("never leaks the raw code into the message", () => {
|
||||
for (const code of BOOKING_VALIDATION_ERROR_CODES) {
|
||||
expect(getFriendlyMessage(code)).not.toContain(code);
|
||||
}
|
||||
});
|
||||
|
||||
it("gives SLOT_UNAVAILABLE a message that doesn't sound like an internal error", () => {
|
||||
expect(getFriendlyMessage("SLOT_UNAVAILABLE").toLowerCase()).toContain("booked");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getFriendlyValidationMessages", () => {
|
||||
it("maps every issue in a validation result", () => {
|
||||
const messages = getFriendlyValidationMessages({
|
||||
valid: false,
|
||||
issues: [
|
||||
{ code: "STAFF_ON_BREAK", message: "internal" },
|
||||
{ code: "BELOW_MIN_NOTICE", message: "internal" },
|
||||
],
|
||||
});
|
||||
expect(messages).toHaveLength(2);
|
||||
expect(messages[0]).toBe(getFriendlyMessage("STAFF_ON_BREAK"));
|
||||
expect(messages[1]).toBe(getFriendlyMessage("BELOW_MIN_NOTICE"));
|
||||
});
|
||||
|
||||
it("returns an empty array for a valid result", () => {
|
||||
expect(getFriendlyValidationMessages({ valid: true, issues: [] })).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getFirstFriendlyMessage", () => {
|
||||
it("returns the first issue's friendly message", () => {
|
||||
const message = getFirstFriendlyMessage({
|
||||
valid: false,
|
||||
issues: [
|
||||
{ code: "BUSINESS_CLOSED", message: "internal" },
|
||||
{ code: "STAFF_ON_LEAVE", message: "internal" },
|
||||
],
|
||||
});
|
||||
expect(message).toBe(getFriendlyMessage("BUSINESS_CLOSED"));
|
||||
});
|
||||
|
||||
it("falls back gracefully when there are no issues", () => {
|
||||
expect(getFirstFriendlyMessage({ valid: true, issues: [] })).toMatch(/went wrong/i);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user