From c472ce2a91cb73441dd01fc1076ae41925df9d7f Mon Sep 17 00:00:00 2001 From: Alexandre Brandizzi Date: Tue, 22 Sep 2026 23:04:13 -0300 Subject: [PATCH] fix: preserve uplift denial message --- .../_components/uplift-requests-section.tsx | 8 +++- .../app/v/uplift-requests-section.test.tsx | 43 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/test/app/v/uplift-requests-section.test.tsx diff --git a/src/app/v/[token]/dispatch/_components/uplift-requests-section.tsx b/src/app/v/[token]/dispatch/_components/uplift-requests-section.tsx index 9fa98227..820c186e 100644 --- a/src/app/v/[token]/dispatch/_components/uplift-requests-section.tsx +++ b/src/app/v/[token]/dispatch/_components/uplift-requests-section.tsx @@ -96,8 +96,12 @@ function useVendorUpliftActions({ if (outcome.outcome === "NoApprovalRequired") { setInfoMessage("No approval required — the existing NTE already covers this amount."); } - } catch { - setFormError("Unable to request the NTE uplift. Please try again."); + } catch (error) { + setFormError( + error instanceof Error && error.message + ? error.message + : "Unable to request the NTE uplift. Please try again.", + ); } finally { setSubmitting(false); } diff --git a/src/test/app/v/uplift-requests-section.test.tsx b/src/test/app/v/uplift-requests-section.test.tsx new file mode 100644 index 00000000..306848fd --- /dev/null +++ b/src/test/app/v/uplift-requests-section.test.tsx @@ -0,0 +1,43 @@ +import { fireEvent, screen, waitFor } from "@testing-library/react"; +import { afterEach, describe, expect, it, vi } from "vitest"; + +import { UpliftRequestsSection } from "@/app/v/[token]/dispatch/_components/uplift-requests-section"; +import { renderWithProviders } from "@/test/test-utils"; + +afterEach(() => { + vi.restoreAllMocks(); +}); + +describe("UpliftRequestsSection create workflow", () => { + it("renders the server denial message when requestUplifts is denied", async () => { + const denialMessage = "Your role can't request uplifts on this work order."; + const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue( + new Response(JSON.stringify({ message: denialMessage }), { + status: 403, + headers: { "Content-Type": "application/json" }, + }), + ); + + renderWithProviders( + undefined)} + />, + { withAuth: false }, + ); + + fireEvent.change(screen.getByLabelText("New total NTE"), { target: { value: "100" } }); + fireEvent.click(screen.getByRole("button", { name: "Request uplift" })); + + await waitFor(() => expect(screen.getByRole("alert")).toHaveTextContent(denialMessage)); + expect(fetchMock).toHaveBeenCalledWith( + expect.stringMatching(/\/api\/vendor-portal\/dispatches\/7\/uplift-request$/), + expect.objectContaining({ method: "POST" }), + ); + }); +});