seahaven-ap/src/mocks/index.test.ts

51 lines
1.6 KiB
TypeScript
Raw Normal View History

import { afterEach, describe, expect, it } from "vitest";
import {
areMocksEnabled,
getMockInvoices,
getMockVendors,
resetMockInvoices,
updateMockInvoicePayDate,
} from "@/mocks";
describe("mocks module", () => {
afterEach(() => {
resetMockInvoices();
});
it("defaults to mocks enabled", () => {
expect(areMocksEnabled()).toBe(true);
});
it("exposes sample invoices and vendors", () => {
expect(getMockVendors().length).toBeGreaterThan(0);
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/,
);
});
});