test: 启用 bun test 并补 todo contract 示例

- package.json 加 "test": "bun test"
- todo.contract.test.ts 给 starter 一个可复制的 colocated 测试样板
  覆盖 valid input / missing field / wrong type 三种 case
This commit is contained in:
2026-04-25 13:31:34 +08:00
parent 8f7744ca0d
commit 6dc7f9f791
2 changed files with 21 additions and 0 deletions
+1
View File
@@ -21,6 +21,7 @@
"db:studio": "drizzle-kit studio", "db:studio": "drizzle-kit studio",
"dev": "bunx --bun vite dev", "dev": "bunx --bun vite dev",
"fix": "biome check --write", "fix": "biome check --write",
"test": "bun test",
"typecheck": "tsc --noEmit" "typecheck": "tsc --noEmit"
}, },
"dependencies": { "dependencies": {
@@ -0,0 +1,20 @@
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)
})
})