fix(work-orders): treat vendor status overlay as local-only on board patch

Board PATCH persists vendorId only. primaryDispatchStatus is optimistic until
the producer returns a live dispatch after vendor save.
This commit is contained in:
Arthur Bassi 2026-08-20 14:47:04 -03:00
parent 493104c56d
commit 972e5913f3
3 changed files with 41 additions and 0 deletions

View file

@ -42,6 +42,7 @@ const LOCAL_ONLY_KEYS = new Set<keyof WorkOrderTablePatch>([
"originalDate",
/** Optimistic overlay only — backend owns isAddOn after schedule ops (SH-184). */
"isAddOn",
"primaryDispatchStatus",
]);
export function isLocalOnlyTablePatch(patch: WorkOrderTablePatch): boolean {

View file

@ -5,6 +5,7 @@ import {
isLocalOnlyTablePatch,
mapDocStatusToApi,
} from "@/domain/work-orders/mappers/work-order-board-patch-mapper";
import { toVendorTablePatch } from "@/domain/work-orders/utils/vendor-assignment-patch";
describe("mapDocStatusToApi", () => {
it("maps NN to NotNeeded", () => {
@ -25,6 +26,10 @@ describe("isLocalOnlyTablePatch", () => {
it("does not treat site as local-only", () => {
expect(isLocalOnlyTablePatch({ site: "BK5" })).toBe(false);
});
it("treats primaryDispatchStatus overlay as local-only", () => {
expect(isLocalOnlyTablePatch({ primaryDispatchStatus: "" })).toBe(true);
});
});
describe("expandTablePatchToBoardFieldOps", () => {
@ -136,6 +141,17 @@ describe("expandTablePatchToBoardFieldOps", () => {
}),
).toEqual([{ field: "vendorId", value: "7" }]);
expect(
expandTablePatchToBoardFieldOps(
toVendorTablePatch({
vendorId: "9",
company: "New Co",
tech: "Pat",
techPhone: "555",
}),
),
).toEqual([{ field: "vendorId", value: "9" }]);
expect(
expandTablePatchToBoardFieldOps({
site: "BK5",

View file

@ -449,6 +449,30 @@ describe("tableRowToClosabilityInput", () => {
});
expect(getClosabilityGaps(input)).toEqual([]);
});
it.each(["Pending", "Sent"] as const)(
"keeps company assignment after vendor save when primary dispatch status is %s",
(primaryDispatchStatus) => {
const input = tableRowToClosabilityInput({
...closableRow,
company: "New Co",
vendorId: "9",
primaryDispatchStatus,
});
expect(input.vendorId).toBe("9");
expect(getClosabilityGaps(input)).not.toContain("Company");
},
);
it("raises Company when leftover Refused remains on the patched vendor id", () => {
const input = tableRowToClosabilityInput({
...closableRow,
company: "New Co",
vendorId: "9",
primaryDispatchStatus: "Refused",
});
expect(getClosabilityGaps(input)).toContain("Company");
});
});
describe("readDetailWoType", () => {