Files
dh-inspeccion-v2/api-v3/test/unit/phase-f4-inspection-close.test.ts
T

29 lines
1.3 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('F4 forbids closing an Inspection while any Act still awaits company outcome', () => {
const service = read('src/inspection-visits/inspection-visit-closure.service.ts');
assert.match(service, /INSPECTION_VISIT_COMPANY_OUTCOME_PENDING/);
assert.match(service, /signature\.status IN \('SIGNED', 'REFUSED', 'ABSENT'\)/);
assert.match(service, /recipient|signature|empresa/i);
});
test('F4 requires all non-cancelled Acts to be sealed before closing the Inspection', () => {
const service = read('src/inspection-visits/inspection-visit-closure.service.ts');
assert.match(service, /INSPECTION_VISIT_ACTS_NOT_SEALED/);
assert.match(service, /act\.closure_sha256 IS NULL/);
assert.match(service, /allActsSealed: true/);
});
test('F4 stamps sealed_at when an Act reaches the physical CLOSED state', () => {
const migration = read('src/database/migrations/1790056800000-phase-f4-sealed-acts.ts');
assert.match(migration, /sealed_at/);
assert.match(migration, /dhv2_f4_stamp_act_seal/);
assert.match(migration, /NEW\.status = 'CLOSED'/);
});