Files
conference-room-booking-system/frontend/src/__tests__/helpers/booking.test.ts
2025-10-02 07:58:28 -04:00

45 lines
1.2 KiB
TypeScript

import {
getEditBookingRoomId,
formatBookingError,
} from "../../helpers/booking";
describe("booking helpers", () => {
function rollingIso(hours: number) {
return new Date(Date.now() + hours * 3600 * 1000).toISOString();
}
it("extracts room id from booking", () => {
expect(
getEditBookingRoomId({
id: "b1",
room_id: "42",
start_time: rollingIso(1),
end_time: rollingIso(2),
})
).toBe("42");
expect(getEditBookingRoomId(null)).toBe("");
});
it("formats booking errors: overlap", () => {
expect(formatBookingError("Overlap detected")).toMatch(/already booked/);
});
it("formats booking errors: capacity", () => {
expect(formatBookingError("Room capacity exceeded")).toMatch(
/exceeds the room's capacity/
);
});
it("formats booking errors: attendee", () => {
expect(formatBookingError("Too many attendees")).toMatch(
/exceeds the room's capacity/
);
});
it("formats booking errors: empty string", () => {
expect(formatBookingError("")).toBe("An unknown error occurred.");
});
it("formats booking errors: other", () => {
expect(formatBookingError("Room unavailable")).toMatch(/Room unavailable/);
});
});