diff --git a/api-v3/test/unit/f4-document-lifecycle-database-contract.test.ts b/api-v3/test/unit/f4-document-lifecycle-database-contract.test.ts index 08de105..c922beb 100644 --- a/api-v3/test/unit/f4-document-lifecycle-database-contract.test.ts +++ b/api-v3/test/unit/f4-document-lifecycle-database-contract.test.ts @@ -9,6 +9,7 @@ const read = (relative: string) => fs.readFileSync(path.join(root, relative), 'u const migration = read('src/database/migrations/1790000600000-f4-align-document-lifecycle-constraints.ts'); const closing = read('src/inspection-closing/inspection-closing.service.ts'); const reports = read('src/inspection-reports/inspection-reports.service.ts'); +const acts = read('src/inspection-acts/inspection-acts.service.ts'); test('F4 PostgreSQL accepts the active Act and report lifecycle states emitted by services', () => { assert.match(migration, /status IN \('WORKING','OFFICIALIZED','FROZEN','CANCELLED'\)/); @@ -18,6 +19,12 @@ test('F4 PostgreSQL accepts the active Act and report lifecycle states emitted b assert.match(closing, /status='SEALED'/); }); +test('F4 PostgreSQL accepts the ACT-NNNNN-DD-MM-YY code generated by the active service', () => { + assert.match(acts, /`ACT-\$\{String\(actNumber\)\.padStart\(5, '0'\)\}-\$\{dateRow\.date_part\}`/); + assert.match(migration, /ACT-\[0-9\]\{5\}-\[0-9\]\{2\}-\[0-9\]\{2\}-\[0-9\]\{2\}/); + assert.match(migration, /ACTA-\[0-9\]\{4\}-\[0-9\]\{6\}/); +}); + test('F4 PostgreSQL accepts LOCKED and SEALED in the immutable Act version ledger', () => { assert.match(migration, /event IN \('CREATED','UPDATED','LOCKED','SEALED','READY','REOPENED','CLOSED','CANCELLED'\)/); assert.match(closing, /InspectionActVersionEvent\.LOCKED/); @@ -40,12 +47,14 @@ test('F4 SEALED rows require closure metadata at database level', () => { assert.match(up, /closure_sha256 ~ '\^\[0-9a-f\]\{64\}\$'/); }); -test('F4 lifecycle rollback translates new states before restoring legacy CHECKs', () => { +test('F4 lifecycle rollback translates new states and codes before restoring legacy CHECKs', () => { const down = migration.slice(migration.indexOf(' public async down(')); const guardRestore = down.indexOf("OLD.status IN ('CLOSED','RECTIFIED')"); - const actTranslation = down.indexOf('UPDATE inspection_acts'); + const codeTranslation = down.indexOf("SET code='ACTA-'"); + const actTranslation = down.indexOf('SET status=CASE'); assert.ok(guardRestore >= 0); - assert.ok(actTranslation > guardRestore, 'Debe restaurarse primero la guarda D5 para poder traducir SEALED a CLOSED'); + assert.ok(codeTranslation > guardRestore, 'Debe restaurarse primero la guarda D5 para traducir códigos F4'); + assert.ok(actTranslation > codeTranslation, 'El código debe traducirse antes de convertir SEALED a CLOSED'); assert.match(down, /WHEN status='LOCKED' THEN 'READY'/); assert.match(down, /WHEN status='SEALED' THEN 'CLOSED'/); assert.match(down, /WHEN event='LOCKED' THEN 'READY'/);