test(work-orders): pin vendor PATCH producer row onto closability

This commit is contained in:
Arthur Bassi 2026-08-20 15:39:39 -03:00
parent d8da3a5048
commit 9a347a67fb
2 changed files with 49 additions and 15 deletions

View file

@ -84,4 +84,18 @@ describe("mapWorkOrderTableRow primaryDispatchStatus", () => {
expect(row.company).toBe("");
expect(row.primaryDispatchStatus).toBe("Sent");
});
it("maps vendor PATCH replacement dispatch as Pending with a new primaryDispatchId", () => {
const row = mapWorkOrderTableRow({
id: 1,
VendorId: 5,
VendorName: "New Co",
PrimaryDispatchStatus: "Pending",
PrimaryDispatchId: 11,
});
expect(row.vendorId).toBe("5");
expect(row.company).toBe("New Co");
expect(row.primaryDispatchStatus).toBe("Pending");
expect(row.primaryDispatchId).toBe(11);
});
});

View file

@ -21,6 +21,7 @@ vi.mock("@/domain/work-orders/api/work-orders-api", () => ({
vi.mock("react-toastify", () => ({ toast: { error: vi.fn() } }));
import { mapWorkOrderTableRow } from "@/domain/work-orders/mappers/work-order-table-row-mapper";
import {
applySchedulePatch,
useWorkOrderTableMutations,
@ -374,13 +375,21 @@ describe("useWorkOrderTableMutations vendor assignment round-trip", () => {
});
it("keeps Company off the gap list when vendor PATCH returns a Pending assignment", async () => {
const returnedRow: WorkOrderTableRow = {
...rowState,
vendorId: "9",
company: "New Co",
primaryDispatchStatus: "Pending",
primaryDispatchId: 11,
};
const returnedRow = mapWorkOrderTableRow({
id: 42,
VendorId: 9,
VendorName: "New Co",
PrimaryDispatchStatus: "Pending",
PrimaryDispatchId: 11,
DispatcherId: "d1",
DispatcherName: "Dispatcher",
CompletedDate: "2026-07-15",
InternalWONumber: "20260623001",
PM: "HVAC",
DocStatus: "Yes",
MediaCount: 1,
WorkOrderType: "PM",
});
patchBoardField.mockResolvedValue(returnedRow);
const onPatch = vi.fn();
@ -409,26 +418,37 @@ describe("useWorkOrderTableMutations vendor assignment round-trip", () => {
await waitFor(() =>
expect(onPatch).toHaveBeenCalledWith(
42,
expect.objectContaining({ primaryDispatchStatus: "Pending" }),
expect.objectContaining({
primaryDispatchStatus: "Pending",
primaryDispatchId: 11,
vendorId: "9",
}),
),
);
expect(patchBoardField).toHaveBeenCalledWith(
42,
expect.objectContaining({ field: "vendorId", value: "9" }),
expect.objectContaining({
field: "vendorId",
value: "9",
dispatchVersion: "disp-v1",
primaryDispatchId: 10,
}),
);
const payload = patchBoardField.mock.calls[0]?.[1] as Record<string, unknown>;
expect(payload).not.toHaveProperty("primaryDispatchStatus");
expect(returnedRow.primaryDispatchId).not.toBe(10);
expect(getClosabilityGaps(tableRowToClosabilityInput(returnedRow))).not.toContain("Company");
});
it("keeps a Company gap when vendor PATCH still returns Refused", async () => {
const returnedRow: WorkOrderTableRow = {
...rowState,
vendorId: "9",
company: "New Co",
primaryDispatchStatus: "Refused",
};
const returnedRow = mapWorkOrderTableRow({
id: 42,
VendorId: 9,
VendorName: "New Co",
PrimaryDispatchStatus: "Refused",
PrimaryDispatchId: 10,
});
patchBoardField.mockResolvedValue(returnedRow);
const onPatch = vi.fn();