test(invoicing): mock useAuth to keep rep-filter a no-op in tests
This commit is contained in:
parent
ed07617827
commit
9cf8e39b65
1 changed files with 22 additions and 0 deletions
|
|
@ -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", () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue