import { describe, expect, it } from "vitest"; import { buildBook } from "./book"; import { lotDetail } from "./fixtures.spec-helper"; const movement = (id: string, createdAt: string, quantity: number, type = "TREATMENT" as const) => ({ id, type, quantity, treatmentId: null, reason: null, userId: null, createdAt, }); describe("buildBook", () => { it("lists the newest booking first and ends at the receipt", () => { const rows = buildBook( lotDetail({ quantity: 20, movements: [movement("b", "2026-08-12T08:00:00.000Z", -3), movement("a", "2026-08-10T08:00:00.000Z", -8)], }), ); expect(rows.map((row) => row.label)).toEqual(["Behandlung", "Behandlung", "Eingang"]); expect(rows.map((row) => row.balance)).toEqual([9, 12, 20]); }); it("keeps the running rest exact to the thousandth", () => { const rows = buildBook( lotDetail({ quantity: 1, movements: [movement("a", "2026-08-10T08:00:00.000Z", -0.1), movement("b", "2026-08-11T08:00:00.000Z", -0.2)], }), ); expect(rows[0].balance).toBe(0.7); }); it("lets a rest fall below zero and keeps the sign", () => { const rows = buildBook(lotDetail({ quantity: 2, movements: [movement("a", "2026-08-10T08:00:00.000Z", -5)] })); expect(rows[0].balance).toBe(-3); }); it("reads the day of a booking as the Berlin calendar day", () => { const rows = buildBook(lotDetail({ movements: [movement("a", "2026-08-10T22:30:00.000Z", -1)] })); expect(rows[0].day).toBe("2026-08-11"); }); });