diff --git a/src/app/(app)/invoicing/page.test.tsx b/src/app/(app)/invoicing/page.test.tsx index aae0211..73e95e2 100644 --- a/src/app/(app)/invoicing/page.test.tsx +++ b/src/app/(app)/invoicing/page.test.tsx @@ -146,6 +146,28 @@ vi.mock("@/app/api/invoicing/customers", async () => { }; }); +// `useAuth` is called by the page after the rep-scoped list filter +// was wired in. The test mocks PB directly (not the auth provider), +// so we have to stub `useAuth` here. Return a non-REP user so the +// filter is a no-op — the test data doesn't carry a `rep` field on +// customers, so a real rep would zero out every row. +// +// The user object lives in `vi.hoisted` so React sees the same +// reference across renders — otherwise the page's `load` callback +// (which now depends on `user`) re-fires every render and the +// PB query blows past the test's `toHaveBeenCalledTimes(2)` bound. +const { mockAuthUser } = vi.hoisted(() => ({ + mockAuthUser: { + id: "user-42", + name: "Casey Booker", + email: "casey@example.com", + user_type: ["BUYER"], + }, +})); +vi.mock("@/components/auth-provider", () => ({ + useAuth: () => ({ user: mockAuthUser, loading: false }), +})); + import Page from "./page"; describe("InvoicingPage", () => {