From 25a262e241d1e02a9d722f8c79c50e7c2e5ce85c Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Mon, 18 May 2026 20:59:43 +0200 Subject: [PATCH] test(schema): cover ObservationSchema + Vertebra + Severity --- tests/unit/schema.observation.test.ts | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/unit/schema.observation.test.ts diff --git a/tests/unit/schema.observation.test.ts b/tests/unit/schema.observation.test.ts new file mode 100644 index 00000000..5a361fb9 --- /dev/null +++ b/tests/unit/schema.observation.test.ts @@ -0,0 +1,69 @@ +import { describe, it, expect } from 'vitest' +import { + ObservationSchema, + VertebraSchema, + SeveritySchema, +} 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('ObservationSchema', () => { + const baseObs = { + id: 'obs-1', + zones: [{ boneId: 'epaule' }], + pathologyIds: [], + freeTextPathologies: [], + 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('rejects empty id', () => { + expect(() => ObservationSchema.parse({ ...baseObs, id: '' })).toThrow() + }) +})