Files
faunosteo/packages/anatomy/tests/importer.guards.test.ts
T

48 lines
1.8 KiB
TypeScript

import { DOCUMENT_DOLLAR_TAG, renderDraftSeedSql } from '../src'
import { mapAnnotation } from '../src/legacy/annotations'
import { assertNothingDropped } from '../src/legacy/catalog'
import { parseAnnotatedSvg } from '../src/legacy/svg'
import { runImport } from './helpers'
/** Guards that never fire on today's data, proven on synthetic inputs. */
const SVG_WITHOUT_EN = `<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">
<circle cx="1" cy="2" r="3" data-anno-id="point-x"
data-anno-name-fr="Garrot" data-anno-category="os"/>
</svg>`
describe('importer guards', () => {
it('throws when a zone loses a vet referral', () => {
const before = { nodes: 10, leaves: 7, vetReferrals: 2 }
const after = { nodes: 10, leaves: 7, vetReferrals: 1 }
expect(() => assertNothingDropped('hip', before, after)).toThrow(
'zone hip: vetReferrals 2 in, 1 out',
)
expect(() => assertNothingDropped('hip', before, before)).not.toThrow()
})
it('copies FR into EN when data-anno-name-en is absent, and says so', () => {
const [legacy] = parseAnnotatedSvg(SVG_WITHOUT_EN, 'x.svg').annotations
const mapped = mapAnnotation(legacy!, {
viewId: 'main',
fileName: 'x.svg',
zoneByNames: new Map(),
})
expect(mapped.annotation.name).toEqual({ fr: 'Garrot', en: 'Garrot' })
expect(mapped.anomalies.map((a) => [a.code, a.level])).toContainEqual([
'annotation.name_en.missing',
'a_valider',
])
})
it('refuses a document that contains the dollar-quote tag', async () => {
const result = await runImport()
const documentJson = JSON.stringify({ note: DOCUMENT_DOLLAR_TAG })
const params = { sheetId: result.sheetId, assets: [], changeNote: 'x' }
expect(() => renderDraftSeedSql({ ...params, documentJson })).toThrow(
DOCUMENT_DOLLAR_TAG,
)
})
})