shoc-frontend-new/src/test/domain/vendors/utils/build-company-notes-patch.test.ts

32 lines
1.3 KiB
TypeScript
Raw Normal View History

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 (SH-321)", () => {
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();
});
});