mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 04:33:11 +00:00
fix: preserve uplift denial message
This commit is contained in:
parent
4965b8a076
commit
c472ce2a91
2 changed files with 49 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
43
src/test/app/v/uplift-requests-section.test.tsx
Normal file
43
src/test/app/v/uplift-requests-section.test.tsx
Normal file
|
|
@ -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(
|
||||
<UpliftRequestsSection
|
||||
token="portal-token"
|
||||
dispatchId={7}
|
||||
currentNte={100}
|
||||
upliftRequests={[]}
|
||||
locked={false}
|
||||
onChanged={vi.fn()}
|
||||
pollDocument={vi.fn(async () => 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" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue