111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
import {
|
||
AnatomicalSheetDocumentSchema,
|
||
validateSheetDocument,
|
||
} from '@faunosteo/domain'
|
||
import {
|
||
buildEquineDraft,
|
||
DRAFT_SEED_SQL_FILE,
|
||
renderDraftArtifacts,
|
||
type DraftResult,
|
||
type ImportResult,
|
||
} from '../src'
|
||
import { changesetOf } from './fixtures/mini-sheet'
|
||
import { runDraft } from './helpers'
|
||
|
||
const VIEW_BOX = { min_x: 0, min_y: 0, width: 1, height: 1 }
|
||
|
||
let result: ImportResult
|
||
let draft: DraftResult
|
||
let artifacts: Record<string, string>
|
||
|
||
beforeAll(async () => {
|
||
;({ result, draft } = await runDraft())
|
||
artifacts = await renderDraftArtifacts(draft, result.anomalies)
|
||
})
|
||
|
||
const REVIEW_HEADINGS = [
|
||
'1. Qualité des données initiales',
|
||
'2. Principales erreurs anatomiques et ostéopathiques',
|
||
'3. Corrections effectuées',
|
||
'4. Ajouts',
|
||
'5. Réorganisations du catalogue',
|
||
'6. Éléments incertains',
|
||
'7. Traductions',
|
||
'8. Points de vigilance clinique',
|
||
'9. Bibliographie',
|
||
'10. Décisions réservées au professionnel',
|
||
]
|
||
|
||
describe('equine working draft (real sources + committed curation)', () => {
|
||
it('validates with zero integrity error', () => {
|
||
const parsed = AnatomicalSheetDocumentSchema.parse(draft.document)
|
||
const errors = validateSheetDocument(parsed).filter(
|
||
(i) => i.severity === 'error',
|
||
)
|
||
expect(errors).toEqual([])
|
||
expect(draft.sheetId).toBe(result.sheetId)
|
||
})
|
||
|
||
it('carries one drawing and the curated content', () => {
|
||
expect(draft.statsBefore.assets).toBe(2)
|
||
expect(draft.statsAfter.assets).toBe(1)
|
||
expect(draft.assets).toHaveLength(1)
|
||
const [main, head] = draft.document.views
|
||
expect(main!.svg_asset_id).toBe(draft.assets[0]!.svg_asset_id)
|
||
expect(head).toMatchObject({
|
||
svg_asset_id: null,
|
||
view_box: { min_x: 60, min_y: 100, width: 500, height: 380 },
|
||
})
|
||
const cd = draft.document.vertebral_config.regions.find(
|
||
(r) => r.code === 'Cd',
|
||
)
|
||
expect(cd!.count_range).toEqual({ min: 15, max: 21 })
|
||
// Carpus zone added, linked from its annotation (CHG carpus_zone).
|
||
const carpus = draft.document.annotations.find((a) => a.id === 'carpus')
|
||
expect(carpus).toMatchObject({ finding_zone_id: 'carpus', kind: 'point' })
|
||
expect(draft.document.finding_zones.some((z) => z.id === 'carpus')).toBe(
|
||
true,
|
||
)
|
||
// Node volume: 792 legacy − SSB duplicates − absent sutures + carpus & flags.
|
||
expect(draft.statsAfter.nodes).toBe(811)
|
||
expect(draft.statsAfter.descriptionsFrOnly).toBe(0)
|
||
})
|
||
|
||
it('lists CHG-000 and the Cd range change in the CHANGELOG', () => {
|
||
const changelog = artifacts['CHANGELOG.md']!
|
||
expect(changelog).toContain('## Comparaison quantitative')
|
||
expect(changelog).toMatch(/\| `CHG-000` .*`view:head\.view_box`/)
|
||
expect(changelog).toMatch(/\| `CHG-\d{3}` .*`region:Cd\.count_range`/)
|
||
})
|
||
|
||
it('writes the ten review sections in order', () => {
|
||
const headings = [
|
||
...artifacts['REVIEW-REPORT.md']!.matchAll(/^## (.+)$/gm),
|
||
].map((m) => m[1])
|
||
expect(headings).toEqual(REVIEW_HEADINGS)
|
||
})
|
||
|
||
it('seeds a converging draft and never publishes', () => {
|
||
const sql = artifacts[DRAFT_SEED_SQL_FILE]!
|
||
expect(sql).toContain('private.insert_sheet_draft')
|
||
expect(sql).toMatch(
|
||
/update public\.anatomical_sheet_versions[\s\S]*status = 'draft'/,
|
||
)
|
||
expect(sql).not.toContain('publish_sheet_version')
|
||
})
|
||
|
||
it('refuses a changeset that reuses the reserved CHG-000', () => {
|
||
const [own] = changesetOf([{ op: 'remove', target: 'zone:hip' }]).changes
|
||
const changeset = { changes: [{ ...own!, id: 'CHG-000' }] }
|
||
const input = { importResult: result, legacyMainSvgBytes: new Uint8Array() }
|
||
expect(() =>
|
||
buildEquineDraft({
|
||
...input,
|
||
headViewBox: VIEW_BOX,
|
||
references: [],
|
||
changeset,
|
||
}),
|
||
).toThrow('CHG-000 is reserved')
|
||
})
|
||
})
|