From 73090d05e46f51163e8b290ac3470af172c26b9d Mon Sep 17 00:00:00 2001 From: Alexandre Brandizzi Date: Fri, 25 Sep 2026 12:26:31 -0300 Subject: [PATCH] fix(auth): keep change-password failures inline without a global toast --- src/domain/auth/use-cases/use-change-password.ts | 1 + .../app/(protected)/account/my-account-page.test.tsx | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/domain/auth/use-cases/use-change-password.ts b/src/domain/auth/use-cases/use-change-password.ts index 90d1d0df..c86e7860 100644 --- a/src/domain/auth/use-cases/use-change-password.ts +++ b/src/domain/auth/use-cases/use-change-password.ts @@ -7,6 +7,7 @@ import type { ChangePasswordPayload } from "@/domain/auth/types/auth-user"; export function useChangePassword(): UseMutationResult { return useMutation({ mutationFn: (data: ChangePasswordPayload) => authApi.changePassword(data), + meta: { suppressErrorToast: true }, onSuccess: () => { toast.success("Password updated"); }, diff --git a/src/test/app/(protected)/account/my-account-page.test.tsx b/src/test/app/(protected)/account/my-account-page.test.tsx index 135b0db5..65c5ad3e 100644 --- a/src/test/app/(protected)/account/my-account-page.test.tsx +++ b/src/test/app/(protected)/account/my-account-page.test.tsx @@ -1,10 +1,12 @@ import { screen, waitFor, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; +import { toast } from "react-toastify"; import { beforeEach, describe, expect, it, vi } from "vitest"; import MyAccountPage from "@/app/(protected)/account"; import * as authApi from "@/domain/auth/api/auth-api"; import type { AuthUser } from "@/domain/auth/types/auth-user"; +import { createAppQueryClient } from "@/lib/query/query-client"; import { renderWithProviders } from "@/test/test-utils"; const { toastSuccessMock } = vi.hoisted(() => ({ toastSuccessMock: vi.fn() })); @@ -30,8 +32,12 @@ vi.mock("react-toastify", () => ({ toast: { success: toastSuccessMock, error: vi.fn(), info: vi.fn() }, })); +/** Uses the app's query client, so the global mutation error toast is live. */ function renderPage() { - return renderWithProviders(, { route: "/account" }); + return renderWithProviders(, { + route: "/account", + queryClient: createAppQueryClient(), + }); } function field(label: RegExp) { @@ -133,5 +139,6 @@ describe("My Account page", () => { expect(await screen.findByText("Current password is incorrect")).toBeInTheDocument(); expect(field(/^current password/i)).toHaveAttribute("aria-invalid", "true"); expect(toastSuccessMock).not.toHaveBeenCalled(); + expect(vi.mocked(toast.error)).not.toHaveBeenCalled(); }); });