forked from imbytecat/fullstack-starter
6dc7f9f791
- package.json 加 "test": "bun test" - todo.contract.test.ts 给 starter 一个可复制的 colocated 测试样板 覆盖 valid input / missing field / wrong type 三种 case
21 lines
678 B
TypeScript
21 lines
678 B
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import { createInsertSchema } from 'drizzle-zod'
|
|
import { generatedFieldKeys } from '@/server/db/fields'
|
|
import { todoTable } from '@/server/db/schema'
|
|
|
|
describe('todo insert schema', () => {
|
|
const insertSchema = createInsertSchema(todoTable).omit(generatedFieldKeys)
|
|
|
|
test('accepts a minimal valid input', () => {
|
|
expect(insertSchema.safeParse({ title: 'buy milk' }).success).toBe(true)
|
|
})
|
|
|
|
test('rejects missing title', () => {
|
|
expect(insertSchema.safeParse({}).success).toBe(false)
|
|
})
|
|
|
|
test('rejects non-string title', () => {
|
|
expect(insertSchema.safeParse({ title: 42 }).success).toBe(false)
|
|
})
|
|
})
|