49 lines
2.7 KiB
TypeScript
49 lines
2.7 KiB
TypeScript
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, /heading\('Hallazgos y fotografías'\)/);
|
|
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</);
|
|
assert.doesNotMatch(page, /Inventario inspeccionado/);
|
|
assert.doesNotMatch(page, /view\.inventories/);
|
|
});
|
|
|
|
test('Acta sealed snapshot excludes Inventory that has no Hallazgo and PDF skips standalone asset media', () => {
|
|
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/);
|
|
});
|