- lib/schemas/idea.ts: ideaCreateSchema, ideaUpdateSchema, ideaPlanMdFrontmatterSchema (yaml-frontmatter contract for materialize-step parser) - lib/idea-status.ts: bidirectional DB↔API mapping, canTransition state-machine guard, isIdeaEditable + isGrillMdEditable + isPlanMdEditable helpers - includes auto-regen docs/erd.svg from prisma generate Tests: 26 cases (status round-trip, transitions valid/invalid, schema validation edge-cases, priority bounds, verify-enum). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
131 lines
3.4 KiB
TypeScript
131 lines
3.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
|
|
import {
|
|
ideaCreateSchema,
|
|
ideaUpdateSchema,
|
|
ideaPlanMdFrontmatterSchema,
|
|
} from '@/lib/schemas/idea'
|
|
|
|
describe('ideaCreateSchema', () => {
|
|
it('accepts minimal valid input', () => {
|
|
const r = ideaCreateSchema.safeParse({ title: 'Plant-watering reminder' })
|
|
expect(r.success).toBe(true)
|
|
})
|
|
|
|
it('trims and enforces non-empty title', () => {
|
|
const r = ideaCreateSchema.safeParse({ title: ' ' })
|
|
expect(r.success).toBe(false)
|
|
})
|
|
|
|
it('rejects oversized title and description', () => {
|
|
expect(ideaCreateSchema.safeParse({ title: 'x'.repeat(201) }).success).toBe(false)
|
|
expect(
|
|
ideaCreateSchema.safeParse({ title: 'ok', description: 'x'.repeat(4001) }).success,
|
|
).toBe(false)
|
|
})
|
|
|
|
it('accepts cuid-like product_id', () => {
|
|
const r = ideaCreateSchema.safeParse({
|
|
title: 'Idee',
|
|
product_id: 'cmohrysyj0000rd17clnjy4tc',
|
|
})
|
|
expect(r.success).toBe(true)
|
|
})
|
|
|
|
it('rejects non-cuid product_id', () => {
|
|
const r = ideaCreateSchema.safeParse({ title: 'Idee', product_id: 'not-a-cuid' })
|
|
expect(r.success).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('ideaUpdateSchema', () => {
|
|
it('allows empty object (no-op update)', () => {
|
|
expect(ideaUpdateSchema.safeParse({}).success).toBe(true)
|
|
})
|
|
|
|
it('allows partial title update', () => {
|
|
expect(ideaUpdateSchema.safeParse({ title: 'Updated' }).success).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('ideaPlanMdFrontmatterSchema', () => {
|
|
const validPlan = {
|
|
pbi: { title: 'Test PBI', priority: 2 },
|
|
stories: [
|
|
{
|
|
title: 'Eerste flow',
|
|
priority: 2,
|
|
tasks: [
|
|
{ title: 'Setup', priority: 2, implementation_plan: '1. Doe X' },
|
|
],
|
|
},
|
|
],
|
|
}
|
|
|
|
it('accepts a minimal valid plan', () => {
|
|
expect(ideaPlanMdFrontmatterSchema.safeParse(validPlan).success).toBe(true)
|
|
})
|
|
|
|
it('requires at least one story', () => {
|
|
const r = ideaPlanMdFrontmatterSchema.safeParse({ ...validPlan, stories: [] })
|
|
expect(r.success).toBe(false)
|
|
})
|
|
|
|
it('requires at least one task per story', () => {
|
|
const r = ideaPlanMdFrontmatterSchema.safeParse({
|
|
...validPlan,
|
|
stories: [{ ...validPlan.stories[0], tasks: [] }],
|
|
})
|
|
expect(r.success).toBe(false)
|
|
})
|
|
|
|
it('validates priority bounds 1-4', () => {
|
|
expect(
|
|
ideaPlanMdFrontmatterSchema.safeParse({
|
|
...validPlan,
|
|
pbi: { ...validPlan.pbi, priority: 5 },
|
|
}).success,
|
|
).toBe(false)
|
|
expect(
|
|
ideaPlanMdFrontmatterSchema.safeParse({
|
|
...validPlan,
|
|
pbi: { ...validPlan.pbi, priority: 0 },
|
|
}).success,
|
|
).toBe(false)
|
|
})
|
|
|
|
it('accepts optional verify_required + verify_only', () => {
|
|
const r = ideaPlanMdFrontmatterSchema.safeParse({
|
|
...validPlan,
|
|
stories: [
|
|
{
|
|
...validPlan.stories[0],
|
|
tasks: [
|
|
{
|
|
title: 'Verify-only task',
|
|
priority: 2,
|
|
verify_required: 'ALIGNED_OR_PARTIAL',
|
|
verify_only: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
expect(r.success).toBe(true)
|
|
})
|
|
|
|
it('rejects invalid verify_required enum', () => {
|
|
const r = ideaPlanMdFrontmatterSchema.safeParse({
|
|
...validPlan,
|
|
stories: [
|
|
{
|
|
...validPlan.stories[0],
|
|
tasks: [
|
|
{ title: 't', priority: 2, verify_required: 'INVALID' },
|
|
],
|
|
},
|
|
],
|
|
})
|
|
expect(r.success).toBe(false)
|
|
})
|
|
})
|