From c1eeb5f078b25c1e39bfefeabde4aaeb6fde2714 Mon Sep 17 00:00:00 2001 From: enlineawork Date: Thu, 10 Sep 2026 20:20:47 -0300 Subject: [PATCH] test: protect CSRF fix, simplified shell and PDF projection --- ...-2-csrf-layout-document-projection.test.ts | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 api-v3/test/unit/f6-2-csrf-layout-document-projection.test.ts diff --git a/api-v3/test/unit/f6-2-csrf-layout-document-projection.test.ts b/api-v3/test/unit/f6-2-csrf-layout-document-projection.test.ts new file mode 100644 index 0000000..de5ff37 --- /dev/null +++ b/api-v3/test/unit/f6-2-csrf-layout-document-projection.test.ts @@ -0,0 +1,51 @@ +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; +import test from 'node:test'; + +function source(path: string): string { + return readFileSync(resolve(process.cwd(), path), 'utf8'); +} + +test('F6.2 planning uses the shared CSRF-aware API requester', () => { + const page = source('../web-v2/src/pages/InspectionVisitCreateF61Page.tsx'); + const api = source('../web-v2/src/lib/api.ts'); + + assert.match(page, /import \{ apiRequest \} from '\.\.\/lib\/api';/); + assert.doesNotMatch(page, /async function requestJson/); + assert.doesNotMatch(page, /fetch\(`\/api\/v3/); + assert.match(page, /apiRequest\('\/inspection-visits'/); + assert.match(api, /headers\.set\('x-csrf-token', token\)/); + assert.match(api, /readCsrfCookie\(\)/); +}); + +test('F6.2 removes the duplicated global operational bar and hidden persisted filters', () => { + const layout = source('../web-v2/src/layout/AppLayout.tsx'); + const context = source('../web-v2/src/context/OperationalContext.tsx'); + + assert.doesNotMatch(layout, /OperationalContextBar/); + assert.match(context, /localStorage\.removeItem\(LEGACY_STORAGE_KEY\)/); + assert.doesNotMatch(context, /localStorage\.setItem/); + assert.match(context, /useState\(''\)/); +}); + +test('F6.2 exposes provisional PDF data contracts for Actas and Informes', () => { + const projection = source('../web-v2/src/components/DocumentPdfProjection.tsx'); + const actPage = source('../web-v2/src/pages/InspectionActEditorPage.tsx'); + const reportPage = source('../web-v2/src/pages/ReportDetailPage.tsx'); + const model = source('../docs/INSPECTION_DOCUMENT_MODEL.md'); + const spec = source('../docs/PDF_PROVISIONAL_STRUCTURE.md'); + + assert.match(projection, /PDF PRELIMINAR · ESTRUCTURA PROYECTADA/); + assert.match(projection, /Contrato de datos estable, renderer reemplazable/); + assert.match(projection, /Identificación y contexto/); + assert.match(projection, /Firmas y manifestaciones/); + assert.match(projection, /GEDO e integridad/); + assert.match(projection, /Anexo final/); + assert.match(actPage, //); + assert.match(reportPage, //); + assert.match(model, /Inspección o visita \| 1 a muchos \| Actas de inspección/); + assert.match(model, /Informe técnico \| 1 a 1 \| Acta fuente/); + assert.match(spec, /Cada INF tiene \*\*una sola Acta fuente\*\*/); + assert.match(spec, /Acta fuente completa como anexo final/); +});