- lib/idea-code.ts: pure formatIdeaCode helper (client-safe, no prisma) - lib/idea-code-server.ts: atomic nextIdeaCode via Prisma row-lock, accepts optional TransactionClient for combining with idea.create - lib/idea-plan-parser.ts: parsePlanMd extracts ---yaml---/body, runs yaml.parse + ideaPlanMdFrontmatterSchema, returns line-info on failure; CRLF-tolerant - adds yaml@^2.8.4 dependency - 8 unit tests (parser happy/missing/yaml-error/zod-error/empty-stories/CRLF; formatIdeaCode pad-3 + overflow) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
21 lines
753 B
TypeScript
21 lines
753 B
TypeScript
import { describe, it, expect } from 'vitest'
|
|
|
|
import { formatIdeaCode } from '@/lib/idea-code'
|
|
|
|
describe('formatIdeaCode', () => {
|
|
it('pads to 3 digits', () => {
|
|
expect(formatIdeaCode(1)).toBe('IDEA-001')
|
|
expect(formatIdeaCode(42)).toBe('IDEA-042')
|
|
expect(formatIdeaCode(999)).toBe('IDEA-999')
|
|
})
|
|
|
|
it('does not truncate beyond pad-width', () => {
|
|
expect(formatIdeaCode(1000)).toBe('IDEA-1000')
|
|
expect(formatIdeaCode(99999)).toBe('IDEA-99999')
|
|
})
|
|
})
|
|
|
|
// Integration-style concurrency-test op nextIdeaCode is in
|
|
// __tests__/integration/ tests die de echte DB raken (zie M12 verificatie-stap).
|
|
// Hier alleen de pure formatter; de increment-logica leunt op Prisma's
|
|
// row-lock in $transaction die we per-database vertrouwen.
|