mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-05 18:52:05 +00:00
Some checks are pending
* feat(locations): derive site areas from state * chore(locations): keep ticket keys out of source comments * feat(locations): manage ordered site contacts --------- Co-authored-by: Codex Review Integration <codex-review@local.invalid>
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
mapLocation,
|
|
mapLocationListItem,
|
|
mapLocationToBackend,
|
|
} from "@/domain/locations/mappers/location-mapper";
|
|
|
|
describe("location contacts hydration", () => {
|
|
it("maps the response contacts array and derives the main contact fields", () => {
|
|
const item = mapLocationListItem({
|
|
id: 1,
|
|
name: "Dallas DC",
|
|
contacts: [
|
|
{ name: "Jane", phone: "(421) 433-0032" },
|
|
{ name: "Bob", phone: "(421) 433-0033" },
|
|
],
|
|
});
|
|
|
|
expect(item.contacts).toEqual([
|
|
{ name: "Jane", phone: "(421) 433-0032" },
|
|
{ name: "Bob", phone: "(421) 433-0033" },
|
|
]);
|
|
expect(item.contact).toBe("Jane");
|
|
expect(item.phone).toBe("(421) 433-0032");
|
|
});
|
|
|
|
it("falls back to legacy contact/phone fields when no contacts array exists", () => {
|
|
const item = mapLocationListItem({
|
|
id: 2,
|
|
contact: "Bob",
|
|
phone: "(312) 555-0100",
|
|
});
|
|
|
|
expect(item.contacts).toBeUndefined();
|
|
expect(item.contact).toBe("Bob");
|
|
expect(item.phone).toBe("(312) 555-0100");
|
|
});
|
|
|
|
it("hydrates detail contacts and mirrors the first row in contact/phone", () => {
|
|
const detail = mapLocation({
|
|
id: 3,
|
|
contacts: [{ id: 31, name: "Carol", phone: "555-0143" }],
|
|
});
|
|
|
|
expect(detail.contacts).toEqual([{ id: 31, name: "Carol", phone: "555-0143" }]);
|
|
expect(detail.contact).toBe("Carol");
|
|
expect(detail.phone).toBe("555-0143");
|
|
});
|
|
|
|
it("keeps legacy detail contact/phone for zero-contact data", () => {
|
|
const detail = mapLocation({ id: 4, contact: "Legacy Person", phone: "555-0199" });
|
|
|
|
expect(detail.contacts).toBeUndefined();
|
|
expect(detail.contact).toBe("Legacy Person");
|
|
expect(detail.phone).toBe("555-0199");
|
|
});
|
|
});
|
|
|
|
describe("mapLocationToBackend contacts payload", () => {
|
|
it("sends trimmed contacts in displayed order and derives legacy fields from the first", () => {
|
|
const payload = mapLocationToBackend({
|
|
name: "Dallas DC",
|
|
address: "3811 Distribution Dr",
|
|
city: "Dallas",
|
|
state: "TX",
|
|
zipCode: "70068",
|
|
contactEmail: "jane@example.com",
|
|
status: "Active",
|
|
contacts: [
|
|
{ id: 41, name: " Jane ", phone: " (421) 433-0032 " },
|
|
{ name: "Bob", phone: "(421) 433-0033" },
|
|
],
|
|
});
|
|
|
|
expect(payload.contacts).toEqual([
|
|
{ id: 41, name: "Jane", phone: "(421) 433-0032" },
|
|
{ name: "Bob", phone: "(421) 433-0033" },
|
|
]);
|
|
expect(payload.contact).toBe("Jane");
|
|
expect(payload.phone).toBe("(421) 433-0032");
|
|
});
|
|
|
|
it("keeps legacy contact/phone untouched when no contacts are provided", () => {
|
|
const payload = mapLocationToBackend({
|
|
name: "Legacy DC",
|
|
contact: "Legacy Person",
|
|
phone: "555-0199",
|
|
});
|
|
|
|
expect(payload.contact).toBe("Legacy Person");
|
|
expect(payload.phone).toBe("555-0199");
|
|
expect(payload.contacts).toEqual([]);
|
|
});
|
|
});
|