Set up unit testing infrastructure

Extract slot generation from book.ts into pure utility for unit testing.
Add 8 API unit tests and 4 web component tests with coverage thresholds.

Closes #39

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit was merged in pull request #42.
This commit is contained in:
groombook-paperclip[bot]
2026-03-18 01:55:02 +00:00
committed by GitHub
parent d718821515
commit cba502e35f
10 changed files with 1046 additions and 26 deletions
+11 -21
View File
@@ -15,13 +15,14 @@ import {
clients,
pets,
} from "@groombook/db";
import {
generateAvailableSlots,
BUSINESS_START_HOUR,
BUSINESS_END_HOUR,
} from "../lib/slots.js";
export const bookRouter = new Hono();
// Business hours (UTC) — 09:0017:00
const BUSINESS_START_HOUR = 9;
const BUSINESS_END_HOUR = 17;
// ─── GET /api/book/services ─────────────────────────────────────────────────
// Public: list active services for the booking flow
@@ -86,23 +87,12 @@ bookRouter.get("/availability", async (c) => {
)
);
const durationMs = service.durationMinutes * 60_000;
const slots: string[] = [];
let slotStart = dayStart.getTime();
while (slotStart + durationMs <= dayEnd.getTime()) {
const slotEnd = slotStart + durationMs;
const hasGroomer = groomers.some(({ id: groomerId }) =>
!booked.some(
(a) =>
a.staffId === groomerId &&
a.startTime.getTime() < slotEnd &&
a.endTime.getTime() > slotStart
)
);
if (hasGroomer) slots.push(new Date(slotStart).toISOString());
slotStart += durationMs;
}
const slots = generateAvailableSlots({
dateStr,
durationMinutes: service.durationMinutes,
groomerIds: groomers.map((g) => g.id),
booked,
});
return c.json(slots);
});