Files
cms.fellies.org/packages/content/src/index.test.ts

48 lines
1.1 KiB
TypeScript

import { describe, expect, it } from "vitest"
import { createPostInputSchema, postSchema, updatePostInputSchema, upsertPostSchema } from "./index"
describe("content schemas", () => {
it("accepts a valid post", () => {
const post = postSchema.parse({
id: "8f0cb474-4f84-4f3c-aeb5-a9f193f5f701",
title: "Hello world",
slug: "hello-world",
body: "Body",
status: "published",
createdAt: new Date(),
updatedAt: new Date(),
})
expect(post.slug).toBe("hello-world")
})
it("rejects invalid create payload", () => {
const result = createPostInputSchema.safeParse({
title: "Hi",
slug: "x",
body: "",
status: "unknown",
})
expect(result.success).toBe(false)
})
it("rejects empty update payload", () => {
const result = updatePostInputSchema.safeParse({})
expect(result.success).toBe(false)
})
it("keeps upsert alias for backward compatibility", () => {
const result = upsertPostSchema.safeParse({
title: "Hi",
slug: "x",
body: "",
status: "unknown",
})
expect(result.success).toBe(false)
})
})