Files
faunosteo/packages/anatomy/tests/seed.golden.test.ts
T

50 lines
1.6 KiB
TypeScript

import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import {
EQUINE_SEED_DIR,
EQUINE_SOURCE_PATHS,
SEED_SQL_FILE,
renderArtifacts,
sha256Hex,
type AssetRecord,
} from '../src'
import { REPO_ROOT, runImport } from './helpers'
const seedDir = join(REPO_ROOT, EQUINE_SEED_DIR)
let artifacts: Record<string, string>
beforeAll(async () => {
artifacts = await renderArtifacts(await runImport())
})
describe('committed equine seed (golden)', () => {
it.each([
'document.json',
'legacy-id-map.json',
'assets.json',
SEED_SQL_FILE,
'IMPORT-REPORT.md',
])('%s equals a fresh run (rerun pnpm import:equine)', async (file) => {
const committed = await readFile(join(seedDir, file), 'utf8')
expect(committed).toBe(artifacts[file])
})
it('copies the SVG assets byte for byte with the recorded sha256', async () => {
const assets = JSON.parse(artifacts['assets.json']!) as AssetRecord[]
const sources = [EQUINE_SOURCE_PATHS.mainSvg, EQUINE_SOURCE_PATHS.headSvg]
for (const [index, asset] of assets.entries()) {
const copy = await readFile(join(seedDir, 'assets', asset.file))
const original = await readFile(join(REPO_ROOT, sources[index]!))
expect(copy.equals(original)).toBe(true)
expect(sha256Hex(copy)).toBe(asset.sha256)
expect(copy.byteLength).toBe(asset.byte_size)
}
})
it('seeds a draft and never publishes', () => {
const sql = artifacts[SEED_SQL_FILE]!
expect(sql).toContain('private.insert_sheet_draft')
expect(sql).not.toContain('publish_sheet_version')
})
})