Reset controlado de datos operativos e históricos, nueva jerarquía manual Departamento → Área → Yacimiento → Instalación → Subinstalación, filtros y administración inline de Hallazgos, y corrección de alta con Área sin Operadora.
87 lines
4.7 KiB
TypeScript
87 lines
4.7 KiB
TypeScript
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/1790087400000-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/1790087400000-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 manual creation permits Area context without requiring an operator', () => {
|
|
const migration = source('src/database/migrations/1790087400000-f5-1-clean-manual-inventory.ts');
|
|
const structure = source('src/asset-master/inventory-structure.service.ts');
|
|
|
|
assert.match(migration, /DROP CONSTRAINT IF EXISTS chk_asset_context_history_context_pair/);
|
|
assert.match(migration, /CHECK \(operator_company_id IS NULL OR operational_area_id IS NOT NULL\)/);
|
|
assert.match(structure, /operator_company_id,inventory_family_id/);
|
|
assert.match(structure, /asset_context_history/);
|
|
assert.match(structure, /operational_area_id,operator_company_id/);
|
|
});
|
|
|
|
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<ViewMode>\('ASSOCIATED'\)/);
|
|
assert.match(panel, /available\.filter\(\(item\) => savedIds\.has\(item\.id\)\)/);
|
|
assert.match(panel, /Buscar dentro de \{viewMode === 'ASSOCIATED' \? 'los asociados' : 'todo el Catálogo'\}/);
|
|
assert.match(panel, /Todos para vincular/);
|
|
assert.match(panel, /Esta clasificación todavía no tiene Hallazgos asociados/);
|
|
});
|
|
|
|
test('F5.1 Configuration manages findings inline and filters Subinstallations by Installation', () => {
|
|
const configPage = source('../web-v2/src/pages/AssetTypesPage.tsx');
|
|
|
|
assert.match(configPage, /replaceInventoryFamilyFindings/);
|
|
assert.match(configPage, /Agregar o quitar/);
|
|
assert.match(configPage, /familyFindingIds/);
|
|
assert.match(configPage, /selectedInstallationFamilyId/);
|
|
assert.match(configPage, /family\.parentFamilyId === selectedInstallationFamilyId/);
|
|
assert.match(configPage, /Filtrar por tipo de Instalación/);
|
|
});
|
|
|
|
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, /<strong>Departamento<\/strong>/);
|
|
assert.match(configPage, /familyId=\$\{familyEditor\.id\}/);
|
|
});
|