shoc-frontend-new/src/test/domain/vendors/utils/build-company-notes-patch.test.ts
Codex Review Integration cd5d4ad1d8 fix(work-orders): keep wizard vendor notes bound to the selected company
Late roster data no longer overwrites notes typed for the current selection.
The notes baseline is keyed by vendor, so a save never patches a previous
company. Changing the primary service clears leftover notes, and a save
with a missing baseline reads the current roster first. Also drops ticket
keys from shipped comments.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 15:18:06 -03:00

31 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildCompanyNotesUpdate } from "@/domain/vendors/utils/build-company-notes-patch";
const baseline = { companyId: 12, rowVersion: "AAAAAAAAB9E=", notes: "Call before arrival" };
describe("buildCompanyNotesUpdate", () => {
it("builds a notes-only additive patch when the notes changed", () => {
expect(buildCompanyNotesUpdate(baseline, " Gate code 4411 ")).toEqual({
companyId: 12,
patch: {
rowVersion: "AAAAAAAAB9E=",
addTechnicians: [],
companyFields: { notes: "Gate code 4411" },
},
});
});
it("skips the write when the notes are unchanged apart from whitespace", () => {
expect(buildCompanyNotesUpdate(baseline, "Call before arrival ")).toBeNull();
});
it("skips the write without a loaded company baseline", () => {
expect(buildCompanyNotesUpdate(null, "New notes")).toBeNull();
expect(buildCompanyNotesUpdate({ ...baseline, companyId: null }, "New notes")).toBeNull();
expect(buildCompanyNotesUpdate({ ...baseline, rowVersion: "" }, "New notes")).toBeNull();
});
it("does not send an emptied field, which the additive patch treats as unchanged", () => {
expect(buildCompanyNotesUpdate(baseline, " ")).toBeNull();
});
});