import { beforeEach, describe, expect, it, vi } from "vitest"; import { createAppQueryClient } from "@/lib/query/query-client"; const toastMocks = vi.hoisted(() => ({ error: vi.fn() })); vi.mock("react-toastify", () => ({ toast: { error: toastMocks.error }, })); describe("createAppQueryClient query cache", () => { beforeEach(() => { toastMocks.error.mockReset(); }); it("does not toast for queries that suppress the error toast", async () => { const queryClient = createAppQueryClient(); await expect( queryClient.fetchQuery({ queryKey: ["suppressed-403"], queryFn: () => Promise.reject(new Error("You do not have permission to perform this action.")), meta: { suppressErrorToast: true }, }), ).rejects.toThrow("You do not have permission"); expect(toastMocks.error).not.toHaveBeenCalled(); }); it("still toasts for queries without suppression", async () => { const queryClient = createAppQueryClient(); await expect( queryClient.fetchQuery({ queryKey: ["unsuppressed-failure"], queryFn: () => Promise.reject(new Error("A server error occurred.")), }), ).rejects.toThrow("A server error occurred."); expect(toastMocks.error).toHaveBeenCalledWith("A server error occurred."); }); });