diff --git a/api/apps/geoprocessing/src/modules/planning-units/planning-units.job.ts b/api/apps/geoprocessing/src/modules/planning-units/planning-units.job.ts index 3b5e7b2f7d..ae89b36c28 100644 --- a/api/apps/geoprocessing/src/modules/planning-units/planning-units.job.ts +++ b/api/apps/geoprocessing/src/modules/planning-units/planning-units.job.ts @@ -18,7 +18,10 @@ type CustomPlanningAreaJob = Required< > > & { planningUnitGridShape: RegularPlanningUnitGridShape }; -type RegularPlanningAreaJob = Omit & { +export type RegularPlanningAreaJob = Omit< + PlanningUnitsJob, + 'planningAreaId' +> & { planningUnitGridShape: RegularPlanningUnitGridShape; }; diff --git a/api/apps/geoprocessing/test/e2e.config.ts b/api/apps/geoprocessing/test/e2e.config.ts index 346fd28160..c25d90bb92 100644 --- a/api/apps/geoprocessing/test/e2e.config.ts +++ b/api/apps/geoprocessing/test/e2e.config.ts @@ -4,6 +4,8 @@ import { PlanningUnitGridShape } from '@marxan/scenarios-planning-unit'; interface OptionsWithCountryCode { countryCode: string; + adminAreaLevel1Id?: string; + adminAreaLevel2Id?: string; } export const E2E_CONFIG: { @@ -25,8 +27,10 @@ export const E2E_CONFIG: { valid: { customArea: (options: OptionsWithCountryCode): PlanningUnitsJob => ({ countryId: options.countryCode, - adminAreaLevel1Id: faker.random.alphaNumeric(7), - adminAreaLevel2Id: faker.random.alphaNumeric(12), + adminAreaLevel1Id: + options.adminAreaLevel1Id ?? faker.random.alphaNumeric(7), + adminAreaLevel2Id: + options.adminAreaLevel2Id ?? faker.random.alphaNumeric(12), planningUnitGridShape: PlanningUnitGridShape.Hexagon, planningUnitAreakm2: 100, projectId: 'a9d965a2-35ce-44b2-8112-50bcdfe98447', diff --git a/api/apps/geoprocessing/test/planning-units-processor.e2e-spec.ts b/api/apps/geoprocessing/test/planning-units-processor.e2e-spec.ts index ced12d58bb..2bf75e5681 100644 --- a/api/apps/geoprocessing/test/planning-units-processor.e2e-spec.ts +++ b/api/apps/geoprocessing/test/planning-units-processor.e2e-spec.ts @@ -1,9 +1,17 @@ import { geoprocessingConnections } from '@marxan-geoprocessing/ormconfig'; +import { + PlanningUnitsGeom, + ProjectsPuEntity, +} from '@marxan-jobs/planning-unit-geometry'; import { PlanningUnitsJob } from '@marxan-jobs/planning-unit-geometry/create.regular.planning-units.dto'; import { Test } from '@nestjs/testing'; -import { TypeOrmModule } from '@nestjs/typeorm'; +import { getRepositoryToken, TypeOrmModule } from '@nestjs/typeorm'; import { Job } from 'bullmq'; -import { PlanningUnitsJobProcessor } from '../src/modules/planning-units/planning-units.job'; +import { In, Repository } from 'typeorm'; +import { + PlanningUnitsJobProcessor, + RegularPlanningAreaJob, +} from '../src/modules/planning-units/planning-units.job'; import { E2E_CONFIG } from './e2e.config'; /** @@ -12,6 +20,9 @@ import { E2E_CONFIG } from './e2e.config'; */ describe('planning units jobs (e2e)', () => { let sut: PlanningUnitsJobProcessor; + let data: PlanningUnitsJob; + let projectsPuRepo: Repository; + let planningUnitsRepo: Repository; beforeEach(async () => { const sandbox = await Test.createTestingModule({ @@ -21,26 +32,50 @@ describe('planning units jobs (e2e)', () => { keepConnectionAlive: true, logging: false, }), + TypeOrmModule.forFeature( + [ProjectsPuEntity, PlanningUnitsGeom], + geoprocessingConnections.default, + ), ], providers: [PlanningUnitsJobProcessor], }).compile(); + projectsPuRepo = sandbox.get(getRepositoryToken(ProjectsPuEntity)); + planningUnitsRepo = sandbox.get(getRepositoryToken(PlanningUnitsGeom)); sut = sandbox.get(PlanningUnitsJobProcessor); }); + afterEach(async () => { + const projectId = data.projectId; + + const projectPus = await projectsPuRepo.find({ projectId }); + const geometriesIds = projectPus.map((projectPu) => projectPu.geomId); + + await planningUnitsRepo.delete({ id: In(geometriesIds) }); + }); + it( 'executes the child job processor with mock data', async () => { + data = E2E_CONFIG.planningUnits.creationJob.valid.customArea({ + countryCode: 'NAM', + adminAreaLevel1Id: 'NAM.13_1', + adminAreaLevel2Id: 'NAM.13.5_1', + }); + const createPlanningUnitsDTO = { id: '1', name: 'create-regular-pu', - data: E2E_CONFIG.planningUnits.creationJob.valid.customArea({ - countryCode: 'NAM', - }), - } as Job; + data, + } as Job; - // TODO do actual verification & cleanup (table: planning_units_geom) after test await expect(sut.process(createPlanningUnitsDTO)).resolves.not.toThrow(); + + const projectPus = await projectsPuRepo.find({ + projectId: data.projectId, + }); + + expect(projectPus.length).toBeGreaterThan(0); }, 50 * 1000, );