89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import {
|
|
createAnnouncementInputSchema,
|
|
createCommissionInputSchema,
|
|
createCustomerInputSchema,
|
|
createNavigationMenuInputSchema,
|
|
createPageInputSchema,
|
|
parsePageBlocks,
|
|
serializePageBlocks,
|
|
updateCommissionStatusInputSchema,
|
|
updateNavigationItemInputSchema,
|
|
} from "./index"
|
|
|
|
describe("domain schemas", () => {
|
|
it("applies announcement defaults", () => {
|
|
const result = createAnnouncementInputSchema.parse({
|
|
title: "Notice",
|
|
message: "Open slots",
|
|
})
|
|
|
|
expect(result.placement).toBe("global_top")
|
|
expect(result.priority).toBe(100)
|
|
expect(result.isVisible).toBe(true)
|
|
})
|
|
|
|
it("validates customer and commission payloads", () => {
|
|
const customer = createCustomerInputSchema.safeParse({
|
|
name: "Ada",
|
|
email: "ada@example.com",
|
|
})
|
|
const commission = createCommissionInputSchema.safeParse({
|
|
title: "Portrait",
|
|
status: "new",
|
|
})
|
|
|
|
expect(customer.success).toBe(true)
|
|
expect(commission.success).toBe(true)
|
|
})
|
|
|
|
it("rejects invalid commission status updates", () => {
|
|
const result = updateCommissionStatusInputSchema.safeParse({
|
|
id: "550e8400-e29b-41d4-a716-446655440000",
|
|
status: "invalid",
|
|
})
|
|
|
|
expect(result.success).toBe(false)
|
|
})
|
|
|
|
it("validates page and navigation payload constraints", () => {
|
|
const page = createPageInputSchema.safeParse({
|
|
title: "About",
|
|
slug: "about",
|
|
content: "About page",
|
|
})
|
|
const menu = createNavigationMenuInputSchema.safeParse({
|
|
name: "Primary",
|
|
slug: "primary",
|
|
})
|
|
const navUpdate = updateNavigationItemInputSchema.safeParse({
|
|
id: "550e8400-e29b-41d4-a716-446655440000",
|
|
sortOrder: -1,
|
|
})
|
|
|
|
expect(page.success).toBe(true)
|
|
expect(menu.success).toBe(true)
|
|
expect(navUpdate.success).toBe(false)
|
|
})
|
|
|
|
it("parses and serializes page blocks with legacy fallback", () => {
|
|
const legacy = parsePageBlocks("Legacy body")
|
|
expect(legacy[0]?.type).toBe("rich_text")
|
|
|
|
const serialized = serializePageBlocks([
|
|
{
|
|
id: "hero-1",
|
|
type: "hero",
|
|
heading: "Hello",
|
|
subheading: null,
|
|
ctaLabel: null,
|
|
ctaHref: null,
|
|
},
|
|
])
|
|
|
|
const parsed = parsePageBlocks(serialized)
|
|
expect(parsed[0]?.type).toBe("hero")
|
|
})
|
|
})
|