test: retire Director review contract under F4
This commit is contained in:
@@ -1,56 +1,66 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
const read = (path: string) => readFileSync(resolve(process.cwd(), path), 'utf8');
|
||||
const migration = read('src/database/migrations/1788631200000-phase-d5-3-22-director-report-review.ts');
|
||||
const review = read('src/inspection-reports/inspection-report-review.service.ts');
|
||||
const controller = read('src/inspection-reports/inspection-report-review.controller.ts');
|
||||
const word = read('src/inspection-reports/inspection-report-word.service.ts');
|
||||
const root = process.cwd();
|
||||
const read = (relative: string) => fs.readFileSync(path.join(root, relative), 'utf8');
|
||||
|
||||
const legacyMigration = read('src/database/migrations/1788631200000-phase-d5-3-22-director-report-review.ts');
|
||||
const f4Removal = read('src/database/migrations/1790000400000-f4-remove-director-report-legacy.ts');
|
||||
const workflow = read('src/inspection-reports/inspection-report-workflow.service.ts');
|
||||
const officializeDto = read('src/inspection-reports/dto/officialize-inspection-report.dto.ts');
|
||||
const delivery = read('src/inspection-reports/inspection-document-delivery.service.ts');
|
||||
const acts = read('src/inspection-acts/inspection-acts.service.ts');
|
||||
const findings = read('src/inspection-findings/inspection-findings.service.ts');
|
||||
|
||||
test('D5.3.22 keeps report corrections as immutable numbered Word revisions', () => {
|
||||
assert.match(migration, /inspection_report_revisions/);
|
||||
assert.match(migration, /UNIQUE \(report_id, revision_number\)/);
|
||||
assert.match(migration, /source IN \('AUTO','DIRECTOR_UPLOAD'\)/);
|
||||
assert.match(word, /'AUTO'/);
|
||||
assert.match(review, /'DIRECTOR_UPLOAD'/);
|
||||
assert.match(review, /current_revision_number = \$2/);
|
||||
test('D5.3.22 revision ledger is retained as historical INF versioning', () => {
|
||||
assert.match(legacyMigration, /inspection_report_revisions/);
|
||||
assert.match(legacyMigration, /UNIQUE \(report_id, revision_number\)/);
|
||||
assert.match(legacyMigration, /current_revision_number/);
|
||||
assert.match(workflow, /inspection_report_revisions/);
|
||||
assert.match(workflow, /current_revision_number/);
|
||||
});
|
||||
|
||||
test('D5.3.22 reserves revision approval and final signature to the Director role', () => {
|
||||
assert.match(migration, /inspection_reports\.revise/);
|
||||
assert.match(migration, /inspection_reports\.review/);
|
||||
assert.match(migration, /inspection_reports\.sign_final/);
|
||||
assert.match(migration, /\('director', 'inspection_reports\.sign_final'\)/);
|
||||
assert.doesNotMatch(migration, /\('admin', 'inspection_reports\.sign_final'\)/);
|
||||
assert.match(review, /role\.code = 'director'/);
|
||||
assert.match(controller, /@RequirePermissions\('inspection_reports\.sign_final'\)/);
|
||||
test('F4 explicitly retires Director review approval and final-signature state', () => {
|
||||
assert.match(f4Removal, /DELETE FROM inspection_document_deliveries/);
|
||||
assert.match(f4Removal, /recipient_kind = 'DIRECTOR'/);
|
||||
assert.match(f4Removal, /DROP COLUMN IF EXISTS approved_revision_id/);
|
||||
assert.match(f4Removal, /DROP COLUMN IF EXISTS approved_by/);
|
||||
assert.match(f4Removal, /DROP COLUMN IF EXISTS approved_at/);
|
||||
assert.match(f4Removal, /DROP COLUMN IF EXISTS review_note/);
|
||||
assert.match(f4Removal, /DROP COLUMN IF EXISTS signed_at/);
|
||||
assert.match(f4Removal, /DROP COLUMN IF EXISTS review_status/);
|
||||
assert.doesNotMatch(f4Removal, /DROP COLUMN IF EXISTS current_revision_number/);
|
||||
});
|
||||
|
||||
test('D5.3.22 approves exactly the latest revision before allowing a final signature', () => {
|
||||
assert.match(review, /revision_number = \$2/);
|
||||
assert.match(review, /approved_revision_id = \$2/);
|
||||
assert.match(review, /review_status = 'APPROVED'/);
|
||||
assert.match(review, /INSPECTION_REPORT_NOT_APPROVED/);
|
||||
assert.match(review, /review_status = 'SIGNED'/);
|
||||
test('F4 removes the active Director review service and controller', () => {
|
||||
assert.equal(fs.existsSync(path.join(root, 'src/inspection-reports/inspection-report-review.service.ts')), false);
|
||||
assert.equal(fs.existsSync(path.join(root, 'src/inspection-reports/inspection-report-review.controller.ts')), false);
|
||||
});
|
||||
|
||||
test('D5.3.22 binds the final Director signature to report and revision hashes', () => {
|
||||
assert.match(migration, /inspection_report_signatures/);
|
||||
assert.match(review, /DH-INSPECTION-REPORT-SIGNATURE-V1/);
|
||||
assert.match(review, /reportFrozenSha256/);
|
||||
assert.match(review, /revisionSha256/);
|
||||
assert.match(review, /sha256CanonicalJson\(payload\)/);
|
||||
assert.match(review, /INSPECTION_REPORT_ALREADY_SIGNED/);
|
||||
test('F4 replaces Director approval with editable INF then immutable GEDO IF officialization', () => {
|
||||
assert.match(workflow, /InspectionReportStatus\.WORKING/);
|
||||
assert.match(workflow, /status='OFFICIALIZED'/);
|
||||
assert.match(workflow, /gedo_if_identifier/);
|
||||
assert.match(workflow, /gedo_officialized_at/);
|
||||
assert.match(workflow, /INSPECTION_REPORT_ALREADY_OFFICIALIZED/);
|
||||
assert.match(officializeDto, /gedoIfIdentifier!/);
|
||||
assert.match(officializeDto, /gedoOfficializedAt!/);
|
||||
assert.match(officializeDto, /@MinLength\(2\)/);
|
||||
assert.match(officializeDto, /@IsISO8601/);
|
||||
});
|
||||
|
||||
test('D5.3.22 changes only the report review layer and preserves inspection immutability', () => {
|
||||
test('F4 delivery has no Director recipient while preserving company office and inspector copies', () => {
|
||||
assert.match(delivery, /'COMPANY' \| 'OFFICE' \| 'INSPECTOR'/);
|
||||
assert.match(delivery, /recipient_kind<>'DIRECTOR'/);
|
||||
assert.doesNotMatch(delivery, /recipientKind:'DIRECTOR'/);
|
||||
});
|
||||
|
||||
test('F4 document workflow changes do not reopen acts or mutate finding history', () => {
|
||||
assert.match(acts, /assertVisitHasNoDraftAct/);
|
||||
assert.match(acts, /INSPECTION_VISIT_DRAFT_ACT_ALREADY_EXISTS/);
|
||||
assert.match(findings, /INSPECTION_FINDING_RESPONSE_IMMUTABLE/);
|
||||
assert.doesNotMatch(migration, /ALTER TABLE inspection_acts/);
|
||||
assert.doesNotMatch(migration, /ALTER TABLE inspection_findings/);
|
||||
assert.doesNotMatch(f4Removal, /ALTER TABLE inspection_acts/);
|
||||
assert.doesNotMatch(f4Removal, /ALTER TABLE inspection_findings/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user