From 3a08972cc366186f9e82d212d74121fa48dddaf7 Mon Sep 17 00:00:00 2001 From: enlineawork Date: Thu, 10 Sep 2026 15:50:12 -0300 Subject: [PATCH] test(F6.1): lock Yacimiento scope review fixes --- ...inspection-yacimiento-scope-review.test.ts | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 api-v3/test/unit/f6-1-inspection-yacimiento-scope-review.test.ts diff --git a/api-v3/test/unit/f6-1-inspection-yacimiento-scope-review.test.ts b/api-v3/test/unit/f6-1-inspection-yacimiento-scope-review.test.ts new file mode 100644 index 0000000..e4ea3e2 --- /dev/null +++ b/api-v3/test/unit/f6-1-inspection-yacimiento-scope-review.test.ts @@ -0,0 +1,72 @@ +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; +import test from 'node:test'; + +const api = (path: string) => readFileSync(resolve(process.cwd(), path), 'utf8'); +const web = (path: string) => readFileSync(resolve(process.cwd(), '..', 'web-v2', path), 'utf8'); + +test('F6.1 field Inventory is bounded by the frozen Yacimiento scope', () => { + const source = api('src/inspection-visits/field-inventory.service.ts'); + + assert.match(source, /COALESCE\(visit\.scope_asset_id, visit\.operational_area_id\) AS "scopeAssetId"/); + assert.match(source, /const effectiveParentId = parentId \?\? context\.scopeAssetId/); + assert.match(source, /const parentId = dto\.parentId \?\? context\.scopeAssetId/); + assert.match(source, /\[parentId, context\.scopeAssetId\]/); + assert.match(source, /\[assetId, context\.scopeAssetId\]/); + assert.match(source, /AS "insideScope"/); + assert.doesNotMatch(source, /insideArea/); +}); + +test('F6.1 field Findings reject Inventory outside the frozen Yacimiento scope', () => { + const source = api('src/inspection-visits/field-findings.service.ts'); + + assert.match(source, /COALESCE\(visit\.scope_asset_id, visit\.operational_area_id\) AS "scopeAssetId"/); + assert.match(source, /AS "insideScope"/); + assert.match(source, /if \(!row\.insideScope\)/); + assert.match(source, /Yacimiento definido como alcance/); + assert.doesNotMatch(source, /AS "insideArea"/); +}); + +test('F6.1 planning preserves Yacimiento and never validates Inventory ownership from Company snapshot', () => { + const source = api('src/inspection-visits/inspection-visits.service.ts'); + + assert.match(source, /const nextScope = dto\.scopeAssetId === undefined \? visit\.scopeAssetId : dto\.scopeAssetId/); + assert.match(source, /validateInspectionPlanningScope\(manager, nextAreaId, nextScope\)/); + assert.match(source, /visit\.scopeAssetId \?\? visit\.operationalAreaId/); + assert.match(source, /visit\.plannedStartAt,/); + assert.doesNotMatch(source, /visit\.scopeAssetId = nextAreaId/); + assert.doesNotMatch(source, /assertAssetsMatchContext/); + assert.doesNotMatch(source, /assertCurrentAssetsMatchContext/); + assert.doesNotMatch(source, /asset\.operator_company_id IS DISTINCT FROM/); +}); + +test('F6.1 creation selects actionable checklist Inventory automatically', () => { + const source = api('src/inspection-visits/inspection-planning-create.service.ts'); + + assert.match(source, /INSERT INTO inspection_visit_assets/); + assert.match(source, /COMPANY_OVERDUE','VERIFICATION_OVERDUE','UPCOMING_CONTROL/); + assert.match(source, /'AUTO_INCLUDED'/); +}); + +test('F6.1 operator choices are resolved at the planned timestamp', () => { + const hierarchy = api('src/inspection-visits/inspection-planning-hierarchy.service.ts'); + const controller = api('src/inspection-visits/inspection-visits.controller.ts'); + const createPage = web('src/pages/InspectionVisitCreateF61Page.tsx'); + + assert.match(hierarchy, /operatorsForArea\([\s\S]*at\?: string/); + assert.match(hierarchy, /relation\.valid_from <= \$2::timestamptz/); + assert.match(hierarchy, /relation\.valid_until > \$2::timestamptz/); + assert.match(controller, /@Query\('at'\) at\?: string/); + assert.match(createPage, /operators\?at=\$\{at\}/); + assert.match(createPage, /\[areaId, plannedStartAt\]/); +}); + +test('F6.1 WEB keeps Area and Yacimiento as separate concepts when editing', () => { + const source = web('src/pages/InspectionVisitEditorF4Page.tsx'); + + assert.doesNotMatch(source, /Área \/ Yacimiento<\/span>/); + assert.match(source, /Área<\/span>/); + assert.match(source, /Yacimiento<\/span>/); + assert.match(source, /scopeAssetId: visit\?\.scopeAsset\?\.id \?\? null/); +});