import 'reflect-metadata'; import assert from 'node:assert/strict'; import test from 'node:test'; import { readFileSync } from 'node:fs'; const userMigration = readFileSync( 'src/database/migrations/1789844700000-phase-f3-1-user-profile.ts', 'utf8', ); const usersService = readFileSync('src/administration/users/users.service.ts', 'utf8'); const dossier = readFileSync('src/asset-master/merged-inventory-dossier.service.ts', 'utf8'); const otherMigration = readFileSync( 'src/database/migrations/1789844800000-phase-f3-1-other-inventory-families.ts', 'utf8', ); test('F3.1 amplía el perfil personal y protege email del Inspector también en DB', () => { assert.match(userMigration, /ADD COLUMN dni/); assert.match(userMigration, /ADD COLUMN phone/); assert.match(userMigration, /ADD COLUMN job_title/); assert.match(userMigration, /ADD COLUMN employee_number/); assert.match(userMigration, /uq_users_dni_not_null/); assert.match(userMigration, /INSPECTOR_EMAIL_REQUIRED/); assert.match(userMigration, /trg_user_roles_inspector_email/); assert.match(userMigration, /trg_users_inspector_email/); }); test('F3.1 exige email al crear o asignar el rol Inspector', () => { assert.match(usersService, /assertInspectorHasEmail\(roles, dto\.email/); assert.match(usersService, /assertInspectorHasEmail\(roles, before\.email\)/); assert.match(usersService, /Los usuarios con rol Inspector deben tener un email válido/); assert.match(usersService, /dto\.email !== undefined && !dto\.email && before\.roles\.some/); }); test('F3.1 dossier canónico agrega alias sin borrar identidad histórica', () => { assert.match(dossier, /inventoryIds = \[canonical\.id, \.\.\.aliases\.map/); assert.match(dossier, /Promise\.all\(inventoryIds\.map/); assert.match(dossier, /historicalInventory/); assert.match(dossier, /kind: 'MERGE'/); assert.match(dossier, /CHRONOLOGICAL_AGGREGATION_WITH_ORIGINAL_IDENTITY/); assert.match(dossier, /requestedWasMerged/); }); test('F3.1 crea familias Otro válidas y asociadas a controles universales', () => { assert.match(otherMigration, /F31-INST-OTRO/); assert.match(otherMigration, /Otro \/ no catalogado/); assert.match(otherMigration, /SUBINSTALLATION/); assert.match(otherMigration, /inventory_family_parent_rules/); assert.match(otherMigration, /F31_UNIVERSAL_FINDINGS/); assert.match(otherMigration, /finding_catalog_item_inventory_families/); });