Files
faunosteo/packages/pdf/tests/helpers/reports.ts
T

72 lines
2.1 KiB
TypeScript

import {
buildSheetSnapshot,
readReportDocument,
ReportSchema,
type Report,
type SheetSnapshot,
} from '@faunosteo/domain'
import { loadDraftSheet, readFixtureJson, type DraftSheet } from './draft'
import {
leavesAsV2Report,
legacyLeaves,
loadLegacyBaseline,
} from './legacy-leaves'
/** The three Phase 0 reports, built with the Phase 0 recipe. */
export const REPORT_NAMES = ['v2full', 'demo', 'v2unresolved'] as const
export type ReportName = (typeof REPORT_NAMES)[number]
export interface GoldenReports {
draft: DraftSheet
reports: Record<ReportName, Report>
snapshots: Record<ReportName, SheetSnapshot>
/** Unresolved findings of `v2unresolved` as the migration counted them. */
unresolvedOfV2Unresolved: number
}
/** sphenoid + ssb (the families the migration cannot place) plus one leaf that resolves. */
function buildV2Unresolved(draft: DraftSheet) {
const leaves = legacyLeaves(loadLegacyBaseline())
const unresolvedFamilies = leaves.filter(
(l) => l.zoneId === 'sphenoid' || l.zoneId === 'ssb',
)
const resolved = leaves.find((l) => l.zoneId === 'frontal')!
return readReportDocument(
leavesAsV2Report([...unresolvedFamilies, resolved]),
draft.migrationMap,
)
}
export function loadGoldenReports(): GoldenReports {
const draft = loadDraftSheet()
const unresolved = buildV2Unresolved(draft)
const reports: Record<ReportName, Report> = {
v2full: readReportDocument(
readFixtureJson('report-v2.full.json'),
draft.migrationMap,
).report,
demo: ReportSchema.parse(readFixtureJson('report-v3.demo.json')),
v2unresolved: unresolved.report,
}
const snapshots = Object.fromEntries(
REPORT_NAMES.map((name) => [
name,
buildSheetSnapshot(draft, reports[name]),
]),
) as Record<ReportName, SheetSnapshot>
return {
draft,
reports,
snapshots,
unresolvedOfV2Unresolved: unresolved.unresolvedFindings,
}
}
/** The 612-leaf legacy report migrated through the draft map (T5). */
export function allLeavesMigrated(draft: DraftSheet) {
return readReportDocument(
leavesAsV2Report(legacyLeaves(loadLegacyBaseline())),
draft.migrationMap,
)
}