2026-08-10 17:32:43 -04:00
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
|
import {
|
|
|
|
|
areMocksEnabled,
|
2026-08-10 18:00:51 -04:00
|
|
|
getMockApprovalPolicies,
|
|
|
|
|
getMockApprovals,
|
|
|
|
|
getMockDepartments,
|
|
|
|
|
getMockGlAccounts,
|
2026-08-10 17:32:43 -04:00
|
|
|
getMockInvoices,
|
2026-08-10 18:00:51 -04:00
|
|
|
getMockPendingApprovals,
|
|
|
|
|
getMockUsers,
|
2026-08-10 17:32:43 -04:00
|
|
|
getMockVendors,
|
2026-08-10 18:00:51 -04:00
|
|
|
resetMockApprovalPolicies,
|
|
|
|
|
resetMockApprovals,
|
|
|
|
|
resetMockDepartments,
|
|
|
|
|
resetMockGlAccounts,
|
2026-08-10 17:32:43 -04:00
|
|
|
resetMockInvoices,
|
2026-08-10 18:00:51 -04:00
|
|
|
resetMockUsers,
|
|
|
|
|
resetMockVendors,
|
|
|
|
|
updateMockApprovalStatus,
|
2026-08-10 17:32:43 -04:00
|
|
|
updateMockInvoicePayDate,
|
2026-08-10 18:00:51 -04:00
|
|
|
upsertMockDepartment,
|
|
|
|
|
upsertMockGlAccount,
|
|
|
|
|
upsertMockVendor,
|
|
|
|
|
upsertMockUser,
|
|
|
|
|
upsertMockApprovalPolicy,
|
2026-08-10 17:32:43 -04:00
|
|
|
} 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 18:00:51 -04:00
|
|
|
resetMockVendors();
|
|
|
|
|
resetMockGlAccounts();
|
|
|
|
|
resetMockDepartments();
|
|
|
|
|
resetMockUsers();
|
|
|
|
|
resetMockApprovalPolicies();
|
|
|
|
|
resetMockApprovals();
|
2026-08-10 17:32:43 -04:00
|
|
|
});
|
|
|
|
|
|
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
|
|
|
});
|
2026-08-10 18:00:51 -04:00
|
|
|
|
|
|
|
|
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/,
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-08-10 16:42:19 -04:00
|
|
|
});
|