fix(uplifts): report a failed approvals queue once, inline, without the global toast

This commit is contained in:
Alexandre Brandizzi 2026-09-25 17:03:15 -03:00
parent a031239259
commit 090c977659
2 changed files with 43 additions and 0 deletions

View file

@ -10,5 +10,8 @@ export function useUpliftsQueue(
queryKey: queryKeys.uplifts.queue(params as Record<string, unknown>),
queryFn: () => upliftsApi.list(params),
placeholderData: keepPreviousData,
// The Uplift Approvals page reports a failed queue inline, so the global toast
// would announce the same failure twice.
meta: { suppressErrorToast: true },
});
}

View file

@ -0,0 +1,40 @@
import { QueryClientProvider } from "@tanstack/react-query";
import { renderHook, waitFor } from "@testing-library/react";
import type { ReactNode } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { upliftsApi } from "@/domain/uplifts/api/uplifts-api";
import { useUpliftsQueue } from "@/domain/uplifts/use-cases/use-uplifts-queue";
import { createAppQueryClient } from "@/lib/query/query-client";
const toastMocks = vi.hoisted(() => ({ error: vi.fn() }));
vi.mock("react-toastify", () => ({
toast: { error: toastMocks.error, success: vi.fn() },
}));
afterEach(() => {
vi.restoreAllMocks();
toastMocks.error.mockReset();
});
describe("useUpliftsQueue", () => {
it("does not show the global error toast, since the approvals page reports the failure inline", async () => {
vi.spyOn(upliftsApi, "list").mockRejectedValue(new Error("Failed to load uplift queue"));
// The real app query client runs the QueryCache's global onError handler, which
// toasts unless the query opts out.
const queryClient = createAppQueryClient();
queryClient.setDefaultOptions({ queries: { retry: false } });
const { result } = renderHook(
() => useUpliftsQueue({ status: "Rejected", page: 1, pageSize: 25 }),
{
wrapper: ({ children }: { children: ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
),
},
);
await waitFor(() => expect(result.current.error).toBeInstanceOf(Error));
expect(toastMocks.error).not.toHaveBeenCalled();
});
});