Files
dh-inspeccion-v2/api-v3/test/unit/phase-d5-6-phase-d-closure.test.ts

95 lines
5.0 KiB
TypeScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
const root = process.cwd();
const read = (relative: string) => fs.readFileSync(path.join(root, relative), 'utf8');
test('D5.6 immutable act closure survives F4 as LOCKED then SEALED', () => {
const acts = read('src/inspection-acts/inspection-acts.service.ts');
const closing = read('src/inspection-closing/inspection-closing.service.ts');
assert.match(acts, /INSPECTION_VISIT_DRAFT_ACT_ALREADY_EXISTS/);
assert.match(closing, /status='LOCKED'/);
assert.match(closing, /final_snapshot=\$2/);
assert.match(closing, /final_sha256=\$3/);
assert.match(closing, /status='SEALED'/);
assert.match(closing, /InspectionActVersionEvent\.SEALED/);
assert.match(closing, /INSPECTION_ACT_LOCK_IS_IMMUTABLE/);
});
test('D5.6 preserves findings responses evidence and verification history as non destructive follow-up', () => {
const findings = read('src/inspection-findings/inspection-findings.service.ts');
const evidence = read('src/inspection-findings/inspection-evidence.service.ts');
const verification = read('src/inspection-verifications/inspection-verifications.service.ts');
const ledger = read('src/inspection-verifications/verification-event-ledger.ts');
assert.match(findings, /INSPECTION_FINDING_RESPONSE_IMMUTABLE/);
assert.match(evidence, /immutable: true/);
assert.match(verification, /VERIFICATION_RESULT_IMMUTABLE/);
assert.match(ledger, /inspection_finding_verification_events/);
});
test('D5.6 keeps Inventory temporal context and contextual finding applicability independent and historical', () => {
const temporal = read('src/asset-master/asset-temporal.service.ts');
const assets = read('src/asset-master/assets.service.ts');
const findings = read('src/inspection-findings/inspection-findings.service.ts');
assert.match(temporal, /asset_context_history/);
assert.match(assets, /asset_context_history/);
assert.match(findings, /FINDING_CATALOG_ITEM_NOT_APPLICABLE/);
assert.match(findings, /finding_catalog_asset_overrides/);
});
test('F4 preserves reviewed web planning and APK-only inspection execution', () => {
const visits = read('src/inspection-visits/inspection-visits.service.ts');
const lifecycle = read('src/inspection-visits/inspection-visit-lifecycle.service.ts');
const policy = read('src/inspection-operations/mobile-inspector-policy.ts');
assert.match(visits, /INSPECTION_CHECKLIST_REQUIRED/);
assert.match(visits, /inspection_visit_checklist_items/);
assert.match(lifecycle, /async start\(/);
assert.match(lifecycle, /assertMobileInspector\(principal\)/);
assert.match(lifecycle, /async close\(/);
assert.match(policy, /transport !== 'bearer'/);
assert.match(policy, /includes\('inspector'\)/);
});
test('D5.6 report generation remains attached to sealing each act', () => {
const closing = read('src/inspection-closing/inspection-closing.service.ts');
const word = read('src/inspection-reports/inspection-report-word.service.ts');
assert.match(closing, /ensureFrozenReport\(manager, actId, principal, request\)/);
assert.match(closing, /ensureWordForAct\(actId\)/);
assert.match(word, /buildInspectionReportWord/);
assert.match(word, /inspection_report_revisions/);
});
test('F4 replaces Director approval with editable INF then immutable GEDO IF officialization', () => {
const removedDirectorReview = path.join(root, 'src/inspection-reports/inspection-report-review.service.ts');
const workflow = read('src/inspection-reports/inspection-report-workflow.service.ts');
assert.equal(fs.existsSync(removedDirectorReview), false);
assert.match(workflow, /InspectionReportStatus\.WORKING/);
assert.match(workflow, /status='OFFICIALIZED'/);
assert.match(workflow, /gedo_if_identifier/);
assert.match(workflow, /INSPECTION_REPORT_ALREADY_OFFICIALIZED/);
assert.doesNotMatch(workflow, /Director de Hidrocarburos/);
});
test('F4 keeps auditable delivery, removes Director recipient and makes SMTP administrable', () => {
const delivery = read('src/inspection-reports/inspection-document-delivery.service.ts');
const smtp = read('src/inspection-reports/smtp-delivery.service.ts');
assert.match(delivery, /ACT_PDF/);
assert.match(delivery, /REPORT_WORD/);
assert.match(delivery, /recipient_kind<>'DIRECTOR'/);
assert.match(delivery, /'COMPANY' \| 'OFFICE' \| 'INSPECTOR'/);
assert.match(smtp, /system_smtp_settings/);
assert.match(smtp, /async saveSettings/);
assert.match(smtp, /source:'DATABASE'/);
assert.match(smtp, /resolveEnvironment/);
assert.match(smtp, /SMTP_SETTINGS_MASTER_KEY/);
});
test('D5.6 remains a historical closure baseline while Phase F introduces explicit migrations', () => {
const migrations = fs.readdirSync(path.join(root, 'src/database/migrations'));
assert.equal(migrations.some((name) => /phase-d5-6/i.test(name)), false);
assert.equal(migrations.some((name) => /phase-f1-1-multi-act-inspections/i.test(name)), true);
assert.equal(migrations.some((name) => /f4-/i.test(name)), true);
});