Files
faunosteo/tests/unit/schema.observation.test.ts
Bastien ChanotandClaude e0abb1efa1 feat(schema): add LateralSideSchema and Bone.lateral for laterality support
Exports LateralSideSchema (z.enum left/right) and LateralSide type.
Adds optional side field to ObservationZoneSchema for bilateral zone distinction.
Covers new schema with 6 dedicated tests (accepts/rejects for both types).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-05-23 22:15:33 +02:00

158 lines
4.2 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import {
ObservationSchema,
VertebraSchema,
SeveritySchema,
FindingSchema,
LateralSideSchema,
ObservationZoneSchema,
} 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('LateralSideSchema', () => {
it('accepts left and right', () => {
expect(LateralSideSchema.parse('left')).toBe('left')
expect(LateralSideSchema.parse('right')).toBe('right')
})
it('rejects unknown side', () => {
expect(() => LateralSideSchema.parse('both')).toThrow()
expect(() => LateralSideSchema.parse('')).toThrow()
})
})
describe('ObservationZoneSchema with side', () => {
it('accepts a zone without side (unpaired)', () => {
expect(() => ObservationZoneSchema.parse({ boneId: 'sternum' })).not.toThrow()
})
it('accepts a zone with side left', () => {
const parsed = ObservationZoneSchema.parse({ boneId: 'knee', side: 'left' })
expect(parsed.side).toBe('left')
})
it('accepts a zone with side right', () => {
const parsed = ObservationZoneSchema.parse({ boneId: 'knee', side: 'right' })
expect(parsed.side).toBe('right')
})
it('accepts two zones with same boneId but different sides', () => {
const obs = {
id: 'obs-1',
zones: [
{ boneId: 'knee', side: 'left' },
{ boneId: 'knee', side: 'right' },
],
findings: [],
freeTextFindings: [],
comment: '',
}
expect(() => ObservationSchema.parse(obs)).not.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()
})
})