shoc-frontend-new/src/test/domain/work-orders/mappers/vendor-dropdown-mapper.test.ts

84 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { mapVendorDropdownItem } from "@/domain/work-orders/mappers/work-order-mapper";
import {
formatVendorDistance,
formatVendorTechnicianLabel,
} from "@/domain/work-orders/utils/vendor-dropdown-label";
describe("mapVendorDropdownItem", () => {
it("maps camelCase dropdown payload", () => {
expect(
mapVendorDropdownItem({
id: 7,
companyName: "Cool Air LLC",
contactName: "Ana Silva",
tradeSpecialties: "HVAC",
address: "100 Main St",
distanceMiles: 4.2,
}),
).toEqual({
id: 7,
companyName: "Cool Air LLC",
contactName: "Ana Silva",
tradeSpecialties: "HVAC",
address: "100 Main St",
distanceMiles: 4.2,
});
});
it("maps PascalCase dropdown payload", () => {
expect(
mapVendorDropdownItem({
Id: "v-1",
CompanyName: "Rooter Pros",
ContactName: "Jon",
TradeSpecialties: "Plumbing",
Address: "200 Ocean Dr",
DistanceMiles: "12",
}),
).toEqual({
id: "v-1",
companyName: "Rooter Pros",
contactName: "Jon",
tradeSpecialties: "Plumbing",
address: "200 Ocean Dr",
distanceMiles: 12,
});
});
});
describe("formatVendorTechnicianLabel", () => {
it("formats contactName · companyName", () => {
expect(
formatVendorTechnicianLabel({
id: 1,
companyName: "Gateway Plumbing",
contactName: "Adam Whyte",
tradeSpecialties: "",
address: "",
distanceMiles: null,
}),
).toBe("Adam Whyte · Gateway Plumbing");
});
it("falls back to company when contact is missing", () => {
expect(
formatVendorTechnicianLabel({
id: 2,
companyName: "Gateway Plumbing",
contactName: "",
tradeSpecialties: "",
address: "",
distanceMiles: null,
}),
).toBe("Gateway Plumbing");
});
});
describe("formatVendorDistance", () => {
it("formats miles", () => {
expect(formatVendorDistance(4.2)).toBe("4.2 mi");
expect(formatVendorDistance(5)).toBe("5 mi");
expect(formatVendorDistance(null)).toBe("");
});
});