mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 03:32:06 +00:00
fix(sites): keep the legacy contact name when an update sends no contacts
This commit is contained in:
parent
c5816f8907
commit
fe0d1a2571
2 changed files with 17 additions and 1 deletions
|
|
@ -235,7 +235,8 @@ export function mapLocationToBackend(location: unknown): Record<string, unknown>
|
||||||
state: item.state ?? "",
|
state: item.state ?? "",
|
||||||
zipCode: item.zipCode ?? "",
|
zipCode: item.zipCode ?? "",
|
||||||
phone: typeof item.sitePhone === "string" ? item.sitePhone.trim() : "",
|
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() : "",
|
contactEmail: typeof item.contactEmail === "string" ? item.contactEmail.trim() : "",
|
||||||
accountId: item.accountId ?? "",
|
accountId: item.accountId ?? "",
|
||||||
contacts,
|
contacts,
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,21 @@ describe("mapLocationToBackend site payload", () => {
|
||||||
expect(bare).not.toHaveProperty("notes");
|
expect(bare).not.toHaveProperty("notes");
|
||||||
expect(full).toMatchObject({ status: "Active", title: "Dallas DC", notes: "Gate code 1234" });
|
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", () => {
|
describe("mapLocation site fields", () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue