import { describe, expect, it } from "vitest"; import { assertTransition, BookingTransitionError, canTransition, notifiesCustomer, statusAfter, type AppointmentStatus, type LifecycleAction, } from "./bookingTransitions"; const ACTIONS: LifecycleAction[] = ["mark_held", "mark_no_show", "cancel", "reschedule", "reassign"]; const TERMINAL: AppointmentStatus[] = ["held", "cancelled", "no_show", "rescheduled"]; describe("booking lifecycle transitions (M06 A.5 / M129)", () => { it("allows every action from scheduled", () => { for (const action of ACTIONS) { expect(canTransition("scheduled", action)).toBe(true); } }); it("forbids every action from a terminal status", () => { for (const status of TERMINAL) { for (const action of ACTIONS) { expect(canTransition(status, action)).toBe(false); } } }); it("assertTransition throws BookingTransitionError on an invalid transition", () => { expect(() => assertTransition("cancelled", "cancel")).toThrow(BookingTransitionError); expect(() => assertTransition("scheduled", "cancel")).not.toThrow(); }); it("maps actions to the resulting status (reassign keeps it unchanged)", () => { expect(statusAfter("mark_held")).toBe("held"); expect(statusAfter("mark_no_show")).toBe("no_show"); expect(statusAfter("cancel")).toBe("cancelled"); expect(statusAfter("reschedule")).toBe("rescheduled"); expect(statusAfter("reassign")).toBeNull(); }); it("flags customer-notifying actions (cancel/reschedule/reassign)", () => { expect(notifiesCustomer("cancel")).toBe(true); expect(notifiesCustomer("reschedule")).toBe(true); expect(notifiesCustomer("reassign")).toBe(true); expect(notifiesCustomer("mark_held")).toBe(false); expect(notifiesCustomer("mark_no_show")).toBe(false); }); });