143 lines
4.3 KiB
TypeScript
143 lines
4.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
AnimalSchema,
|
|
FindingSchema,
|
|
LateralSideSchema,
|
|
ObservationSchema,
|
|
PractitionerSchema,
|
|
ReportSchema,
|
|
ReportZoneSchema,
|
|
SeveritySchema,
|
|
VertebraSchema,
|
|
} from '../src'
|
|
|
|
const finding = {
|
|
findingZoneId: 'z',
|
|
path: ['a'],
|
|
labelFrSnapshot: 'a',
|
|
labelEnSnapshot: 'a',
|
|
}
|
|
const observation = {
|
|
id: 'o1',
|
|
zones: [],
|
|
findings: [],
|
|
freeTextFindings: [],
|
|
comment: '',
|
|
}
|
|
const report = {
|
|
version: 3,
|
|
id: 'r1',
|
|
createdAt: '2026-10-01T00:00:00Z',
|
|
date: '2026-10-01',
|
|
practitioner: { name: 'P' },
|
|
animal: { speciesId: 'equine', name: 'A' },
|
|
owner: { name: 'O' },
|
|
sheet: { sheetId: 's', versionId: null, documentSha256: 'a'.repeat(64) },
|
|
observations: [],
|
|
conclusion: '',
|
|
recommendations: '',
|
|
}
|
|
|
|
describe('report v3 leaf schemas', () => {
|
|
it('FindingSchema rejects empty path and empty findingZoneId', () => {
|
|
expect(FindingSchema.safeParse(finding).success).toBe(true)
|
|
expect(FindingSchema.safeParse({ ...finding, path: [] }).success).toBe(
|
|
false,
|
|
)
|
|
expect(
|
|
FindingSchema.safeParse({ ...finding, findingZoneId: '' }).success,
|
|
).toBe(false)
|
|
})
|
|
|
|
it('LateralSideSchema rejects both and empty', () => {
|
|
expect(LateralSideSchema.safeParse('left').success).toBe(true)
|
|
expect(LateralSideSchema.safeParse('both').success).toBe(false)
|
|
expect(LateralSideSchema.safeParse('').success).toBe(false)
|
|
})
|
|
|
|
it('VertebraSchema rejects index 0 and non-integer index', () => {
|
|
expect(VertebraSchema.safeParse({ region: 'C', index: 1 }).success).toBe(
|
|
true,
|
|
)
|
|
expect(VertebraSchema.safeParse({ region: 'C', index: 0 }).success).toBe(
|
|
false,
|
|
)
|
|
expect(VertebraSchema.safeParse({ region: 'C', index: 1.5 }).success).toBe(
|
|
false,
|
|
)
|
|
})
|
|
|
|
it('ObservationSchema rejects an empty id', () => {
|
|
expect(ObservationSchema.safeParse(observation).success).toBe(true)
|
|
expect(
|
|
ObservationSchema.safeParse({ ...observation, id: '' }).success,
|
|
).toBe(false)
|
|
})
|
|
|
|
it('SeveritySchema accepts the three codes only', () => {
|
|
for (const c of ['mild', 'moderate', 'severe'])
|
|
expect(SeveritySchema.safeParse(c).success).toBe(true)
|
|
expect(SeveritySchema.safeParse('légère').success).toBe(false)
|
|
expect(SeveritySchema.safeParse('unknown').success).toBe(false)
|
|
})
|
|
|
|
it('ReportZoneSchema rejects an empty annotationId', () => {
|
|
const zone = { annotationId: 'a', viewId: 'main' }
|
|
expect(ReportZoneSchema.safeParse(zone).success).toBe(true)
|
|
expect(
|
|
ReportZoneSchema.safeParse({ ...zone, annotationId: '' }).success,
|
|
).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('report v3 document and identity', () => {
|
|
it('ReportSchema validates nextAppointment variants', () => {
|
|
const date = { kind: 'date', date: '2026-11-01' }
|
|
const period = { kind: 'period', text: 'dans 3 semaines' }
|
|
expect(
|
|
ReportSchema.safeParse({ ...report, nextAppointment: date }).success,
|
|
).toBe(true)
|
|
expect(
|
|
ReportSchema.safeParse({ ...report, nextAppointment: period }).success,
|
|
).toBe(true)
|
|
expect(
|
|
ReportSchema.safeParse({ ...report, nextAppointment: { kind: 'other' } })
|
|
.success,
|
|
).toBe(false)
|
|
})
|
|
|
|
it('PractitionerSchema rejects an empty name', () => {
|
|
expect(PractitionerSchema.safeParse({ name: '' }).success).toBe(false)
|
|
})
|
|
|
|
it('AnimalSchema rejects an empty speciesId', () => {
|
|
expect(AnimalSchema.safeParse({ speciesId: '', name: 'A' }).success).toBe(
|
|
false,
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('report v3 permissive boundaries', () => {
|
|
it('strips unknown keys silently', () => {
|
|
const out = ReportSchema.parse({ ...report, foo: 1 })
|
|
expect('foo' in out).toBe(false)
|
|
})
|
|
|
|
it('accepts a vertebra index above any region count (bounds are a sheet concern)', () => {
|
|
expect(VertebraSchema.safeParse({ region: 'C', index: 99 }).success).toBe(
|
|
true,
|
|
)
|
|
})
|
|
|
|
it('accepts an unregistered speciesId', () => {
|
|
const animal = { speciesId: 'dragon', name: 'A' }
|
|
expect(ReportSchema.safeParse({ ...report, animal }).success).toBe(true)
|
|
})
|
|
|
|
it('accepts orphan findings citing a zone absent from zones (D5)', () => {
|
|
const orphan = { ...observation, findings: [finding] }
|
|
const out = ReportSchema.safeParse({ ...report, observations: [orphan] })
|
|
expect(out.success).toBe(true)
|
|
})
|
|
})
|