import { afterEach, describe, expect, it } from "vitest"; import { areMocksEnabled, getMockApprovalPolicies, getMockApprovals, getMockDepartments, getMockGlAccounts, getMockInvoices, getMockPendingApprovals, getMockUsers, getMockVendors, resetMockApprovalPolicies, resetMockApprovals, resetMockDepartments, resetMockGlAccounts, resetMockInvoices, resetMockUsers, resetMockVendors, updateMockApprovalStatus, updateMockInvoicePayDate, upsertMockDepartment, upsertMockGlAccount, upsertMockVendor, upsertMockUser, upsertMockApprovalPolicy, } from "@/mocks"; describe("mocks module", () => { afterEach(() => { resetMockInvoices(); resetMockVendors(); resetMockGlAccounts(); resetMockDepartments(); resetMockUsers(); resetMockApprovalPolicies(); resetMockApprovals(); }); 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/, ); }); it("seeds settings entities and supports upsert", () => { expect(getMockVendors().length).toBeGreaterThanOrEqual(4); expect(getMockGlAccounts().length).toBeGreaterThanOrEqual(3); expect(getMockDepartments().length).toBeGreaterThanOrEqual(3); expect(getMockUsers().length).toBeGreaterThanOrEqual(3); expect(getMockApprovalPolicies().length).toBeGreaterThanOrEqual(3); const vendor = upsertMockVendor({ id: "vendor-new", name: "New Vendor", email: "new@example.com", defaultPaymentMethod: "ach", }); expect(getMockVendors().some((row) => row.id === vendor.id)).toBe(true); upsertMockGlAccount({ id: "gl-new", code: "9999", name: "Misc" }); expect(getMockGlAccounts().some((row) => row.id === "gl-new")).toBe(true); upsertMockDepartment({ id: "dept-new", code: "NEW", name: "New Dept" }); expect(getMockDepartments().some((row) => row.id === "dept-new")).toBe(true); upsertMockUser({ id: "user-new", name: "New User", email: "new.user@seahaven.example", role: "approver", }); expect(getMockUsers().some((row) => row.id === "user-new")).toBe(true); upsertMockApprovalPolicy({ id: "policy-new", name: "Ad hoc", amountThreshold: 250, approverRole: "admin", }); expect(getMockApprovalPolicies().some((row) => row.id === "policy-new")).toBe(true); }); it("lists pending approvals and updates status", () => { const pending = getMockPendingApprovals(); expect(pending.length).toBeGreaterThanOrEqual(2); expect(getMockApprovals().length).toBeGreaterThanOrEqual(pending.length); const first = pending[0]; const updated = updateMockApprovalStatus(first.id, "approved"); expect(updated.status).toBe("approved"); expect(getMockPendingApprovals().some((row) => row.id === first.id)).toBe(false); }); it("throws when updating an unknown approval", () => { expect(() => updateMockApprovalStatus("missing", "rejected")).toThrow( /Mock approval not found/, ); }); });