diff --git a/api-v3/test/unit/f4-multi-act-lifecycle.test.ts b/api-v3/test/unit/f4-multi-act-lifecycle.test.ts index a06f47e..93c6a4c 100644 --- a/api-v3/test/unit/f4-multi-act-lifecycle.test.ts +++ b/api-v3/test/unit/f4-multi-act-lifecycle.test.ts @@ -10,6 +10,7 @@ const closing = read('src/inspection-closing/inspection-closing.service.ts'); const lifecycle = read('src/inspection-visits/inspection-visit-lifecycle.service.ts'); const acts = read('src/inspection-acts/inspection-acts.service.ts'); const findings = read('src/inspection-findings/inspection-findings.service.ts'); +const fieldFindings = read('src/inspection-visits/field-findings.service.ts'); const actEntity = read('src/database/entities/inspection-act.entity.ts'); test('F4 keeps finalized acts irreversible', () => { @@ -24,6 +25,16 @@ test('F4 permits multiple acts per inspection but only one simultaneous draft', assert.match(actEntity, /uq_inspection_acts_one_draft_per_visit/); assert.match(actEntity, /where: "status = 'DRAFT'"/); assert.doesNotMatch(actEntity, /uq_inspection_acts_visit['"]/); + + const createBody = acts.slice(acts.indexOf(' async create('), acts.indexOf(' async update(')); + const singleDraftGuard = acts.slice( + acts.indexOf(' private async assertVisitHasNoDraftAct('), + acts.indexOf(' private async assertVisitAssets('), + ); + assert.match(createBody, /this\.assertVisitOpen\(visit\)/); + assert.match(createBody, /this\.assertVisitHasNoDraftAct\(manager, visitId\)/); + assert.match(singleDraftGuard, /WHERE visit_id = \$1 AND status = 'DRAFT'/); + assert.doesNotMatch(singleDraftGuard, /LOCKED|SEALED/); }); test('F4 act locking is independent from inspection-wide verification completion', () => { @@ -55,6 +66,20 @@ test('F4 blocks finding creation and editing once the act is locked', () => { assert.match(updateBody, /this\.assertActEditable\(act, visit\)/); }); +test('F4 field finding flow only targets a draft act of the same in-progress inspection', () => { + const createBody = fieldFindings.slice(fieldFindings.indexOf(' async create('), fieldFindings.indexOf(' private async requireGate(')); + const draftGuard = fieldFindings.slice( + fieldFindings.indexOf(' private async requireDraftAct('), + fieldFindings.lastIndexOf('\n}'), + ); + assert.match(createBody, /this\.requireDraftAct\(visitId, dto\.actId\)/); + assert.match(createBody, /this\.findings\.create\(act\.id, payload, principal, request\)/); + assert.match(fieldFindings, /row\.visitStatus !== 'IN_PROGRESS'/); + assert.match(draftGuard, /act\.status !== 'DRAFT'/); + assert.match(draftGuard, /FIELD_FINDING_ACT_NOT_DRAFT/); + assert.match(draftGuard, /WHERE visit_id = \$1::uuid[\s\S]*AND status = 'DRAFT'/); +}); + test('F4 sealing requires inspector signature and exactly one resolved company manifestation', () => { const closeBody = closing.slice(closing.indexOf(' async close('), closing.indexOf(' async signatureContent(')); assert.match(closeBody, /INSPECTION_ACT_INSPECTOR_SIGNATURE_REQUIRED/);