import { describe, expect, it } from "vitest"; import { describeAuditEntry, fieldLabel, formatAuditValue } from "./audit-format"; describe("audit-format", () => { it("labels known and unknown fields", () => { expect(fieldLabel("selling_price")).toBe("Selling price"); expect(fieldLabel("order_item_details.invoice")).toBe("Invoice"); expect(fieldLabel("order_item_details.split")).toBe("Split"); expect(fieldLabel("drv_collected_at")).toBe("Drv collected at"); }); it("formats money, markup, status and invoice values", () => { expect(formatAuditValue("cost_price", 2.6)).toBe( new Intl.NumberFormat("en-ZA", { style: "currency", currency: "ZAR" }).format(2.6), ); expect(formatAuditValue("markup", 25)).toBe("25%"); expect(formatAuditValue("item_status", "ready_invoice")).toBe("ready invoice"); expect(formatAuditValue("order_item_details.invoice", { number: "INV10983", date: "2026-09-25" })).toBe( "INV10983 (2026-09-25)", ); expect(formatAuditValue("notes", "")).toBe("—"); expect(formatAuditValue("in_stock", true)).toBe("Yes"); }); it("describes entries", () => { expect(describeAuditEntry({ collection: "quote_items", action: "update", label: "M16 bolt" })).toBe( 'Edited line "M16 bolt"', ); expect(describeAuditEntry({ collection: "quotes", action: "update", label: "Q1" })).toBe("Updated the quote"); expect(describeAuditEntry({ collection: "quote_attachments", action: "pdf_generated", label: "x.pdf" })).toBe( "Generated the quote PDF", ); }); });