import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; import test from 'node:test'; import assert from 'node:assert/strict'; const api = (path: string) => readFileSync(resolve(process.cwd(), 'src', path), 'utf8'); const web = (path: string) => readFileSync(resolve(process.cwd(), '..', 'web-v2', 'src', path), 'utf8'); test('Acta PDF renders Hallazgos and finding evidence, never standalone Inventory or field photos', () => { const source = api('inspection-reports/inspection-act-pdf-builder.ts'); assert.match(source, /section\('5\. Hallazgos'\)/); assert.match(source, /item\.findingId === text\(finding\.id\)/); assert.doesNotMatch(source, /Instalaciones inspeccionadas/); assert.doesNotMatch(source, /Otras instalaciones inspeccionadas/); assert.doesNotMatch(source, /item\.assetId === text\(finding\.assetId\)/); }); test('Dashboard Acta shows only Hallazgos and evidence directly attached to them', () => { const media = web('features/inspections/InspectionActMediaPanel.tsx'); const editor = web('pages/InspectionActEditorPage.tsx'); assert.match(media, /listInspectionFindingEvidence/); assert.doesNotMatch(media, /listInspectionActFieldMedia/); assert.doesNotMatch(media, /getAssetMediaBlob/); assert.doesNotMatch(media, /Fotos de otras instalaciones/); assert.doesNotMatch(editor, /Instalaciones inspeccionadas/); }); test('Company signing view exposes Hallazgos as Acta content without a standalone Inventory list', () => { const service = api('inspection-closing/company-signature-invite.service.ts'); const viewBody = service.slice(service.indexOf(' async view(token: string)'), service.indexOf(' async sign(')); const page = web('pages/CompanySignaturePage.tsx'); assert.match(viewBody, /findings/); assert.doesNotMatch(viewBody, /inventories/); assert.match(page, />Hallazgos { const closing = api('inspection-closing/inspection-closing.service.ts'); const pdfService = api('inspection-reports/inspection-act-pdf.service.ts'); const snapshotBody = closing.slice(closing.indexOf(' private async buildLockedSnapshot('), closing.indexOf(' private async deadlinePolicy(')); assert.match(snapshotBody, /EXISTS \(\s*SELECT 1 FROM inspection_findings finding/); assert.match(snapshotBody, /finding\.asset_id=asset\.id/); assert.match(snapshotBody, /finding\.status<>'VOIDED'/); assert.match(pdfService, /fieldImages\(actId, false\)/); assert.match(pdfService, /includeAssetPhotos \? await this\.dataSource\.query/); }); test('Acta PDF explains each Hallazgo with frozen territorial, technical and recurrence context', () => { const pdf = api('inspection-reports/inspection-act-pdf-builder.ts'); const closing = api('inspection-closing/inspection-closing.service.ts'); assert.match(pdf, /Contexto territorial y operativo/); assert.match(pdf, /Inspector\/a responsable/); assert.match(pdf, /Tipo de instalación/); assert.match(pdf, /Qué se constató/); assert.match(pdf, /Referencia de catálogo/); assert.match(pdf, /Normativa \/ Base legal/); assert.match(pdf, /Reincidencia/); assert.match(pdf, /Alcance de la inspección/); assert.match(pdf, /scopeTypeCode/); assert.match(pdf, /Antecedente relacionado/); assert.match(closing, /DH-ACT-LIFECYCLE-V5/); assert.match(closing, /AS department/); assert.match(closing, /AS "leadInspector"/); assert.match(closing, /AS "installationTypeName"/); assert.match(closing, /AS recurrence/); const service = api('inspection-reports/inspection-act-pdf.service.ts'); assert.match(service, /yacimiento_from_findings/); });