mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-05 04:52:07 +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>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
locationDefaultValues,
|
|
locationSchema,
|
|
type LocationFormValues,
|
|
} from "@/domain/locations/schemas/location-schema";
|
|
|
|
const validBase: LocationFormValues = {
|
|
...locationDefaultValues,
|
|
name: "Dallas DC",
|
|
address: "3811 Distribution Dr",
|
|
city: "Dallas",
|
|
state: "TX",
|
|
zipCode: "70068",
|
|
contactEmail: "jane@example.com",
|
|
};
|
|
|
|
describe("locationSchema contacts", () => {
|
|
it("accepts one fully populated contact", () => {
|
|
const result = locationSchema.safeParse({
|
|
...validBase,
|
|
contacts: [{ name: "Jane", phone: "(421) 433-0032" }],
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
it("requires at least one contact", () => {
|
|
const result = locationSchema.safeParse({ ...validBase, contacts: [] });
|
|
|
|
expect(result.success).toBe(false);
|
|
if (!result.success) {
|
|
expect(result.error.issues[0]?.message).toBe("At least one contact is required");
|
|
}
|
|
});
|
|
|
|
it("requires a name and a phone on every row", () => {
|
|
const result = locationSchema.safeParse({
|
|
...validBase,
|
|
contacts: [
|
|
{ name: "Jane", phone: "" },
|
|
{ name: " ", phone: "(421) 433-0032" },
|
|
],
|
|
});
|
|
|
|
expect(result.success).toBe(false);
|
|
if (!result.success) {
|
|
const messages = result.error.issues.map((issue) => issue.message);
|
|
expect(messages).toContain("Phone is required");
|
|
expect(messages).toContain("Contact person is required");
|
|
}
|
|
});
|
|
|
|
it("trims name and phone values on parse", () => {
|
|
const result = locationSchema.safeParse({
|
|
...validBase,
|
|
contacts: [{ name: " Jane ", phone: " (421) 433-0032 " }],
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
if (result.success) {
|
|
expect(result.data.contacts[0]).toEqual({ name: "Jane", phone: "(421) 433-0032" });
|
|
}
|
|
});
|
|
});
|