104 lines
3.4 KiB
TypeScript
104 lines
3.4 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('keeps the catalog volumes and carries one drawing', () => {
|
|
expect(draft.statsAfter.nodes).toBe(draft.statsBefore.nodes)
|
|
expect(draft.statsAfter.leaves).toBe(draft.statsBefore.leaves)
|
|
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 })
|
|
})
|
|
|
|
it('lists CHG-000 and CHG-001 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-001` .*`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')
|
|
})
|
|
})
|