fix(sites): keep the legacy contact name when an update sends no contacts

This commit is contained in:
Alexandre Brandizzi 2026-09-25 12:23:18 -03:00
parent c5816f8907
commit fe0d1a2571
2 changed files with 17 additions and 1 deletions

View file

@ -235,7 +235,8 @@ export function mapLocationToBackend(location: unknown): Record<string, unknown>
state: item.state ?? "",
zipCode: item.zipCode ?? "",
phone: typeof item.sitePhone === "string" ? item.sitePhone.trim() : "",
contact: mainContact ? mainContact.name : "",
// A caller without a contacts list (e.g. address-only sync) keeps the stored legacy name.
contact: mainContact ? mainContact.name : readString(item, "contact").trim(),
contactEmail: typeof item.contactEmail === "string" ? item.contactEmail.trim() : "",
accountId: item.accountId ?? "",
contacts,

View file

@ -107,6 +107,21 @@ describe("mapLocationToBackend site payload", () => {
expect(bare).not.toHaveProperty("notes");
expect(full).toMatchObject({ status: "Active", title: "Dallas DC", notes: "Gate code 1234" });
});
it("keeps the legacy contact name when the caller sends no contacts list", () => {
const addressOnly = mapLocationToBackend({
name: "DAL1",
address: "3811 Distribution Dr",
contact: "Jane Doe",
});
const withContacts = mapLocationToBackend({
contact: "Jane Doe",
contacts: [{ name: "Bob", phone: "(421) 433-0033" }],
});
expect(addressOnly.contact).toBe("Jane Doe");
expect(withContacts.contact).toBe("Bob");
});
});
describe("mapLocation site fields", () => {