mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 06:53:12 +00:00
fix(work-orders): omit non-positive primaryDispatchId on board patches
A GET echo of 0 on primaryDispatchId made vendor PATCH fail InvalidDispatch.
This commit is contained in:
parent
d255fb6b91
commit
72417bbb77
3 changed files with 65 additions and 1 deletions
|
|
@ -84,7 +84,7 @@ export function buildBoardPatchPayload(
|
|||
if (row.dispatchRowVersion) {
|
||||
payload.dispatchVersion = row.dispatchRowVersion;
|
||||
}
|
||||
if (row.primaryDispatchId != null) {
|
||||
if (row.primaryDispatchId != null && row.primaryDispatchId > 0) {
|
||||
payload.primaryDispatchId = row.primaryDispatchId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,6 +205,25 @@ describe("buildBoardPatchPayload", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("omits non-positive primaryDispatchId on dispatch fields", () => {
|
||||
const payload = buildBoardPatchPayload(
|
||||
{ field: "vendorId", value: "7" },
|
||||
{
|
||||
rowVersion: "wo-v1",
|
||||
dispatchRowVersion: "disp-v1",
|
||||
primaryDispatchId: 0,
|
||||
},
|
||||
);
|
||||
|
||||
expect(payload).toEqual({
|
||||
field: "vendorId",
|
||||
value: "7",
|
||||
workOrderVersion: "wo-v1",
|
||||
dispatchVersion: "disp-v1",
|
||||
});
|
||||
expect(payload).not.toHaveProperty("primaryDispatchId");
|
||||
});
|
||||
|
||||
it("omits dispatch version for WO-only fields", () => {
|
||||
const payload = buildBoardPatchPayload(
|
||||
{ field: "siteCode", value: "BK5" },
|
||||
|
|
|
|||
|
|
@ -439,6 +439,7 @@ describe("useWorkOrderTableMutations vendor assignment round-trip", () => {
|
|||
);
|
||||
const payload = patchBoardField.mock.calls[0]?.[1] as Record<string, unknown>;
|
||||
expect(payload).not.toHaveProperty("primaryDispatchStatus");
|
||||
expect(payload.primaryDispatchId).toBe(10);
|
||||
expect(returnedRow.primaryDispatchId).not.toBe(10);
|
||||
expect(getClosabilityGaps(tableRowToClosabilityInput(returnedRow))).not.toContain("Company");
|
||||
});
|
||||
|
|
@ -484,6 +485,50 @@ describe("useWorkOrderTableMutations vendor assignment round-trip", () => {
|
|||
);
|
||||
expect(getClosabilityGaps(tableRowToClosabilityInput(returnedRow))).toContain("Company");
|
||||
});
|
||||
|
||||
it("omits non-positive primaryDispatchId from the vendor PATCH payload", async () => {
|
||||
rowState = { ...rowState, primaryDispatchId: 0 };
|
||||
const returnedRow = mapWorkOrderTableRow({
|
||||
id: 42,
|
||||
VendorId: 9,
|
||||
VendorName: "New Co",
|
||||
PrimaryDispatchStatus: "Pending",
|
||||
PrimaryDispatchId: 11,
|
||||
});
|
||||
patchBoardField.mockResolvedValue(returnedRow);
|
||||
|
||||
const onPatch = vi.fn();
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
useWorkOrderTableMutations({
|
||||
onPatch,
|
||||
clearPatch: () => undefined,
|
||||
getRow: () => rowState,
|
||||
}),
|
||||
{ wrapper: makeWrapper() },
|
||||
);
|
||||
|
||||
act(() => {
|
||||
result.current.patchField(
|
||||
42,
|
||||
toVendorTablePatch({
|
||||
vendorId: "9",
|
||||
company: "New Co",
|
||||
tech: "",
|
||||
techPhone: "",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
await waitFor(() => expect(patchBoardField).toHaveBeenCalled());
|
||||
const payload = patchBoardField.mock.calls[0]?.[1] as Record<string, unknown>;
|
||||
expect(payload).toMatchObject({
|
||||
field: "vendorId",
|
||||
value: "9",
|
||||
dispatchVersion: "disp-v1",
|
||||
});
|
||||
expect(payload).not.toHaveProperty("primaryDispatchId");
|
||||
});
|
||||
});
|
||||
|
||||
describe("useWorkOrderTableMutations patchField success callbacks", () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue