Files
faunosteo/tests/unit/schema.observation.test.ts
T
Bastien ChanotandClaude Opus 4.7 d08d773d74 feat(schema): bump report to v2 + observation findings + drop pathology
ObservationSchema now carries a hierarchical Finding (zoneId + path +
labelFrSnapshot + labelEnSnapshot + requiresVetReferral?) plus a renamed
freeTextFindings list, replacing the flat pathologyIds /
freeTextPathologies pair. Snapshot labels keep already-exported reports
readable if the catalog is later edited.

ReportSchema.version bumped from 1 → 2. PDF import surfaces a distinct,
French-language error message on legacy v1 attachments instead of the
generic "not an osteo PDF" line, via a new IncompatibleReportVersionError
detected before the strict Zod parse runs.

Store seed and tests updated for the new shape. The standalone Pathology
Zod schema and its test are removed — the new findings tree is the single
source of truth for what an observation can carry.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 03:48:57 +02:00

114 lines
2.9 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import {
ObservationSchema,
VertebraSchema,
SeveritySchema,
FindingSchema,
} from '@/domain/schema/observation'
describe('SeveritySchema', () => {
it('accepts the three documented values', () => {
expect(SeveritySchema.parse('légère')).toBe('légère')
expect(SeveritySchema.parse('modérée')).toBe('modérée')
expect(SeveritySchema.parse('sévère')).toBe('sévère')
})
it('rejects unknown severity', () => {
expect(() => SeveritySchema.parse('critique')).toThrow()
})
})
describe('VertebraSchema', () => {
it('accepts a region+index pair', () => {
expect(VertebraSchema.parse({ region: 'T', index: 12 })).toEqual({
region: 'T',
index: 12,
})
})
it('rejects index 0', () => {
expect(() => VertebraSchema.parse({ region: 'C', index: 0 })).toThrow()
})
it('rejects unknown region', () => {
expect(() => VertebraSchema.parse({ region: 'X', index: 1 })).toThrow()
})
})
describe('FindingSchema', () => {
const base = {
zoneId: 'sphenoid',
path: ['sphenoid-dysfunctions', 'physiological', 'flexion'],
labelFrSnapshot: 'Flexion',
labelEnSnapshot: 'Flexion',
}
it('accepts a minimal finding', () => {
expect(() => FindingSchema.parse(base)).not.toThrow()
})
it('accepts the optional vet-referral flag', () => {
expect(() =>
FindingSchema.parse({ ...base, requiresVetReferral: true }),
).not.toThrow()
})
it('rejects an empty path', () => {
expect(() => FindingSchema.parse({ ...base, path: [] })).toThrow()
})
it('rejects an empty zoneId', () => {
expect(() => FindingSchema.parse({ ...base, zoneId: '' })).toThrow()
})
})
describe('ObservationSchema', () => {
const baseObs = {
id: 'obs-1',
zones: [{ boneId: 'epaule' }],
findings: [],
freeTextFindings: [],
comment: '',
}
it('accepts a minimal observation', () => {
expect(() => ObservationSchema.parse(baseObs)).not.toThrow()
})
it('accepts a spine-zone observation with precise vertebrae', () => {
const obs = {
...baseObs,
zones: [
{
boneId: 'thoracic-vertebrae-spine-zone',
vertebrae: [
{ region: 'T', index: 12 },
{ region: 'T', index: 13 },
],
},
],
}
expect(() => ObservationSchema.parse(obs)).not.toThrow()
})
it('accepts an observation with findings and free-text additions', () => {
const obs = {
...baseObs,
findings: [
{
zoneId: 'sphenoid',
path: ['sphenoid-dysfunctions', 'physiological', 'flexion'],
labelFrSnapshot: 'Flexion',
labelEnSnapshot: 'Flexion',
},
],
freeTextFindings: ['note libre'],
}
expect(() => ObservationSchema.parse(obs)).not.toThrow()
})
it('rejects empty id', () => {
expect(() => ObservationSchema.parse({ ...baseObs, id: '' })).toThrow()
})
})