WFDASH-WEBAPP/src/lib/audit-format.test.ts
Dave 7555196166 feat(audit): implement audit trail for delivery notes and orders
- Added an audit trail feature that logs every create, update, and delete action on delivery notes and orders, capturing detailed changes per field.
- Introduced the `AuditTimeline` component to display the history of changes for delivery notes and orders, enhancing traceability.
- Updated the `page.tsx` files for delivery notes and orders to fetch and display audit logs, ensuring users can view the history of modifications.
- Enhanced the `package.json` with a new migration script for setting up the audit log functionality.

This feature improves accountability and transparency in the management of delivery notes and orders.
2026-09-30 01:48:44 +02:00

35 lines
1.5 KiB
TypeScript

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",
);
});
});