shoc-frontend-new/src/test/domain/locations/schemas/location-schema.test.ts
Alexandre Brandizzi 07734d8361
Some checks are pending
Frontend checks / Build and test (push) Waiting to run
Frontend checks / governance (push) Waiting to run
Frontend checks / Visual regression (push) Waiting to run
Deploy dev content / Deploy shoc-frontend-new-dev through Terraform (push) Waiting to run
SH-138: manage ordered site contacts (#191)
* 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>
2026-09-16 14:53:58 -03:00

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" });
}
});
});