Files
dh-inspeccion-v2/api-v3/test/unit/f6-1-findings-mobile-open.test.ts
T
admin c71afab9af
DH V2 CI / API · typecheck, tests, build (push) Successful in 5m16s
Android CI / RC / Android · lint, tests, debug APK, release compile (push) Failing after 6m13s
DH V2 CI / WEB · typecheck, build (push) Successful in 4m52s
DH V2 CI / Docker / migrations / production images (push) Skipped
DH V2 CI / Promote verified main to deploy (push) Skipped
fix(android): scope mobile inspections to yacimiento
2026-09-16 07:33:03 -03:00

84 lines
4.9 KiB
TypeScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import test from 'node:test';
function source(path: string) {
return readFileSync(resolve(process.cwd(), path), 'utf8');
}
test('F6.1 allows direct findings only on Yacimiento, Instalacion and Subinstalacion', () => {
const findings = source('src/inspection-visits/field-findings.service.ts');
assert.match(findings, /\['yacimiento', 'instalacion', 'subinstalacion'\]\.includes\(assetTypeCode\)/);
assert.match(findings, /FIELD_FINDING_TARGET_LEVEL_INVALID/);
assert.match(findings, /Los Hallazgos pueden registrarse sobre Yacimiento, Instalación o Subinstalación/);
assert.match(findings, /assetTypeCode !== 'yacimiento' && !row\.inventoryFamilyId/);
assert.match(findings, /FIELD_FINDING_FAMILY_REQUIRED/);
});
test('F6.1 uses contextual type catalog for Yacimiento and keeps OTROS/add-another everywhere', () => {
const findings = source('src/inspection-visits/field-findings.service.ts');
const resolver = source('src/inspection-findings/f3-finding-catalog-resolver.service.ts');
const catalog = source('src/inspection-findings/finding-catalog.service.ts');
const androidFinding = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/ui/FieldFindingScreen.kt');
assert.match(findings, /canAddAnother: true/);
assert.match(resolver, /typeCode\.toLowerCase\(\) === 'yacimiento'/);
assert.match(resolver, /contextualCatalog\.listApplicableForAsset\(assetId, query\)/);
assert.match(resolver, /catalogSource: 'ASSET_TYPE'/);
assert.match(catalog, /finding_catalog_item_asset_types mapping/);
assert.match(catalog, /finding_catalog_asset_overrides override/);
assert.match(resolver, /code: 'OTHER'/);
assert.match(resolver, /label: 'OTROS'/);
assert.match(androidFinding, /ExposedDropdownMenuBox/);
assert.match(androidFinding, /Otro \/ No está en la lista/);
assert.match(androidFinding, /También podés registrar otro Hallazgo sobre el mismo Inventario/);
});
test('F6.14 mobile planning requires Departamento → Área → Yacimiento → Operadora before opening', () => {
const controller = source('src/inspection-visits/inspection-visits.controller.ts');
const hierarchy = source('src/inspection-visits/inspection-planning-hierarchy.service.ts');
const dto = source('src/inspection-visits/dto/open-mobile-inspection.dto.ts');
assert.match(controller, /@Get\('mobile\/planning-context\/departments'\)/);
assert.match(controller, /@Get\('mobile\/planning-context\/departments\/:departmentId\/areas'\)/);
assert.match(controller, /@Get\('mobile\/planning-context\/areas\/:areaId\/yacimientos'\)/);
assert.match(controller, /@Get\('mobile\/planning-context\/yacimientos\/:yacimientoId\/operators'\)/);
assert.match(controller, /@Post\('mobile\/open'\)/);
assert.match(controller, /validateMobileSelection/);
assert.match(controller, /scopeAssetId: dto\.scopeAssetId/);
assert.match(controller, /leadInspectorUserId: principal\.userId/);
assert.match(controller, /this\.lifecycle\.plan\(created\.id/);
assert.match(controller, /this\.lifecycle\.start\(created\.id/);
assert.match(hierarchy, /Departamento → Área → Yacimiento → Operadora/);
assert.match(dto, /departmentId!: string/);
assert.match(dto, /operationalAreaId!: string/);
assert.match(dto, /scopeAssetId!: string/);
assert.match(dto, /operatorCompanyId!: string/);
});
test('F6.14 Android selects the full territorial chain and enters Actas for an active inspection', () => {
const client = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/data/MobileInspectionOpen.kt');
const home = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/ui/MobileHomeScreen.kt');
const root = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/ui/ModernVisitRoot.kt');
const acts = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/ui/ModernMobileActsScreen.kt');
const gate = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/ui/LoginGate.kt');
assert.match(client, /planning-context\/departments/);
assert.match(client, /departments\/\{departmentId\}\/areas/);
assert.match(client, /areas\/\{areaId\}\/yacimientos/);
assert.match(client, /yacimientos\/\{yacimientoId\}\/operators/);
assert.match(client, /OpenMobileInspectionRequest\(departmentId, areaId, yacimientoId, companyId\)/);
assert.match(home, /1\. Departamento/);
assert.match(home, /2\. Área/);
assert.match(home, /3\. Yacimiento/);
assert.match(home, /4\. Operadora/);
assert.match(home, /Abrir inspección y continuar al Acta/);
assert.match(home, /model\.openVisit\(opened\.id\)/);
assert.match(root, /if \(visit\.status == "IN_PROGRESS"\) ModernVisitScreen\.ACTS/);
assert.match(root, /Buscar Yacimiento, Instalación o Subinstalación/);
assert.match(acts, /Elegí el Yacimiento, una Instalación o una Subinstalación/);
assert.match(gate, /else -> MobileHomeScreen\(model\)/);
});