2026-08-10 17:32:43 -04:00
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
|
import {
|
|
|
|
|
areMocksEnabled,
|
|
|
|
|
getMockInvoices,
|
|
|
|
|
getMockVendors,
|
|
|
|
|
resetMockInvoices,
|
|
|
|
|
updateMockInvoicePayDate,
|
|
|
|
|
} from "@/mocks";
|
2026-08-10 16:42:19 -04:00
|
|
|
|
|
|
|
|
describe("mocks module", () => {
|
2026-08-10 17:32:43 -04:00
|
|
|
afterEach(() => {
|
|
|
|
|
resetMockInvoices();
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-10 16:42:19 -04:00
|
|
|
it("defaults to mocks enabled", () => {
|
|
|
|
|
expect(areMocksEnabled()).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("exposes sample invoices and vendors", () => {
|
|
|
|
|
expect(getMockVendors().length).toBeGreaterThan(0);
|
2026-08-10 17:32:43 -04:00
|
|
|
expect(getMockInvoices().length).toBeGreaterThanOrEqual(6);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("seeds at least two invoices per dashboard tab", () => {
|
|
|
|
|
const invoices = getMockInvoices();
|
|
|
|
|
const pending = invoices.filter((invoice) => invoice.status === "pending_approval");
|
|
|
|
|
const ready = invoices.filter((invoice) => invoice.status === "approved");
|
|
|
|
|
|
|
|
|
|
expect(pending.length).toBeGreaterThanOrEqual(2);
|
|
|
|
|
expect(ready.length).toBeGreaterThanOrEqual(2);
|
|
|
|
|
expect(invoices.every((invoice) => invoice.invoiceNumbers && invoice.amount >= 0)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("updates pay date in the mutable mock store", () => {
|
|
|
|
|
const before = getMockInvoices().find((invoice) => invoice.id === "inv-1");
|
|
|
|
|
expect(before).toBeDefined();
|
|
|
|
|
|
|
|
|
|
const updated = updateMockInvoicePayDate("inv-1", "2026-08-18");
|
|
|
|
|
expect(updated.payDate).toBe("2026-08-18");
|
|
|
|
|
|
|
|
|
|
const after = getMockInvoices().find((invoice) => invoice.id === "inv-1");
|
|
|
|
|
expect(after?.payDate).toBe("2026-08-18");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("throws when updating an unknown invoice", () => {
|
|
|
|
|
expect(() => updateMockInvoicePayDate("missing", "2026-08-18")).toThrow(
|
|
|
|
|
/Mock invoice not found/,
|
|
|
|
|
);
|
2026-08-10 16:42:19 -04:00
|
|
|
});
|
|
|
|
|
});
|