From 80a65c9b7d1a858ad282e515cb58bf9855ec4ac4 Mon Sep 17 00:00:00 2001 From: enlineawork Date: Wed, 9 Sep 2026 07:55:33 -0300 Subject: [PATCH] =?UTF-8?q?F5.1:=20contratos=20de=20reset,=20jerarqu=C3=AD?= =?UTF-8?q?a=20y=20filtro=20de=20Hallazgos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...-1-clean-manual-inventory-contract.test.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 api-v3/test/unit/f5-1-clean-manual-inventory-contract.test.ts diff --git a/api-v3/test/unit/f5-1-clean-manual-inventory-contract.test.ts b/api-v3/test/unit/f5-1-clean-manual-inventory-contract.test.ts new file mode 100644 index 0000000..0c1c880 --- /dev/null +++ b/api-v3/test/unit/f5-1-clean-manual-inventory-contract.test.ts @@ -0,0 +1,63 @@ +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) { + return readFileSync(resolve(process.cwd(), path), 'utf8'); +} + +test('F5.1 clean start deletes domain instances and audit history but preserves master configuration by contract', () => { + const migration = source('src/database/migrations/1790087300000-f5-1-clean-manual-inventory.ts'); + assert.match(migration, /TRUNCATE TABLE assets CASCADE/); + assert.match(migration, /TRUNCATE TABLE audit_events/); + assert.match(migration, /TRUNCATE TABLE administrative_departments CASCADE/); + assert.match(migration, /TRUNCATE TABLE finding_catalog_item_inventory_families/); + assert.doesNotMatch(migration, /TRUNCATE TABLE inventory_families/); + assert.doesNotMatch(migration, /TRUNCATE TABLE finding_catalog_items/); + assert.doesNotMatch(migration, /TRUNCATE TABLE users/); +}); + +test('F5.1 canonical hierarchy starts at Departamento and Area is no longer root', () => { + const migration = source('src/database/migrations/1790087300000-f5-1-clean-manual-inventory.ts'); + const dto = source('src/asset-master/dto/create-inventory-structure.dto.ts'); + const structure = source('src/asset-master/inventory-structure.service.ts'); + + assert.match(dto, /'DEPARTAMENTO'/); + assert.match(structure, /DEPARTAMENTO: 'departamento'/); + assert.match(structure, /AREA: 'departamento'/); + assert.match(structure, /Departamento → Área → Yacimiento → Instalación → Subinstalación/); + assert.match(migration, /child_code='area' AND parent_code<>'departamento'/); + assert.match(migration, /WHERE lower\(code\)='area'/); + assert.match(migration, /SET can_be_root=false/); +}); + +test('F5.1 Inventory browser exposes every canonical level instead of filtering by is_inventory_instance', () => { + const browser = source('src/asset-master/inventory-browser.service.ts'); + const controller = source('src/asset-master/inventory-browser.controller.ts'); + + assert.match(browser, /'departamento','area','yacimiento','instalacion','subinstalacion'/); + assert.match(browser, /case 'departamento': return 'area'/); + assert.doesNotMatch(browser, /['"]asset\.is_inventory_instance=true['"]/); + assert.match(controller, /@Get\('departments'\)/); + assert.match(controller, /@Get\('companies'\)/); +}); + +test('F5.1 Finding Catalog defaults to associated findings and exposes all items only for linking', () => { + const panel = source('../web-v2/src/features/inspections/FindingCatalogTypeApplicabilityPanel.tsx'); + assert.match(panel, /type ViewMode = 'ASSOCIATED' \| 'ALL'/); + assert.match(panel, /useState\('ASSOCIATED'\)/); + assert.match(panel, /available\.filter\(\(item\) => savedIds\.has\(item\.id\)\)/); + assert.match(panel, /Todos para vincular/); + assert.match(panel, /Esta clasificación todavía no tiene Hallazgos asociados/); +}); + +test('F5.1 Web creation and configuration expose Departamento as the physical root', () => { + const createPage = source('../web-v2/src/pages/InventoryCreatePage.tsx'); + const configPage = source('../web-v2/src/pages/AssetTypesPage.tsx'); + assert.match(createPage, /kind: 'DEPARTAMENTO'/); + assert.match(createPage, /AREA:'Departamento'/); + assert.match(createPage, /Datos opcionales/); + assert.match(configPage, /Departamento<\/strong>/); + assert.match(configPage, /familyId=\$\{familyEditor\.id\}/); +});