From 3c38e28db00037b5286e545b8662d8acc685707f Mon Sep 17 00:00:00 2001 From: andrea rota Date: Fri, 16 Feb 2024 12:51:03 +0000 Subject: [PATCH] wait for feature to be ready after uploading a shapefile --- .../upload-feature/upload-feature.e2e-spec.ts | 5 ++-- .../upload-feature/upload-feature.fixtures.ts | 23 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/api/apps/api/test/upload-feature/upload-feature.e2e-spec.ts b/api/apps/api/test/upload-feature/upload-feature.e2e-spec.ts index 7a562240d1..7190918739 100644 --- a/api/apps/api/test/upload-feature/upload-feature.e2e-spec.ts +++ b/api/apps/api/test/upload-feature/upload-feature.e2e-spec.ts @@ -37,6 +37,7 @@ test(`if tagging info is included in DTO but invalid, then error is returned and name, description, invalidTag1, + { skipWaitingForFeatureToBeReady: true }, // needed as this feature will never be actually created ); expect(result1.status).toBe(HttpStatus.BAD_REQUEST); fixtures.ThenInvalidTagErrorWasReturned(result1); @@ -46,6 +47,7 @@ test(`if tagging info is included in DTO but invalid, then error is returned and name, description, invalidTag2, + { skipWaitingForFeatureToBeReady: true }, // needed as this feature will never be actually created ); expect(result2.status).toBe(HttpStatus.BAD_REQUEST); fixtures.ThenMaxLengthErrorWasReturned(result2); @@ -132,10 +134,9 @@ test('should delete feature_amounts_per_planning_unit data related to a feature const result = await fixtures.WhenUploadingCustomFeature(name, description); - await fixtures.ThenGeoFeaturesAreCreated(result, name, description); await fixtures.ThenFeatureAmountsFromShapefileAreCreated(name); await fixtures.WhenDeletingFeatureForProject(name); await fixtures.ThenFeatureAmountsPerPlanningUnitDataIsDeletedForFeatureWithGivenId( - name, + result.body.id, ); }); diff --git a/api/apps/api/test/upload-feature/upload-feature.fixtures.ts b/api/apps/api/test/upload-feature/upload-feature.fixtures.ts index b10da23b5e..3122875bf6 100644 --- a/api/apps/api/test/upload-feature/upload-feature.fixtures.ts +++ b/api/apps/api/test/upload-feature/upload-feature.fixtures.ts @@ -20,6 +20,7 @@ import { } from '@marxan-jobs/planning-unit-geometry'; import { PlanningUnitGridShape } from '@marxan/scenarios-planning-unit'; import { GivenPuSquareGridGeometryExists } from '../../../geoprocessing/test/steps/given-pu-geometries-exists'; +import { waitForFeatureToBeReady } from '../utils/wait-for-feature-to-be-ready.utils'; export const getFixtures = async () => { const app = await bootstrapApplication(); @@ -145,6 +146,9 @@ export const getFixtures = async () => { name: string, description: string, tagName?: string, + options?: { + skipWaitingForFeatureToBeReady?: boolean; + }, ) => { const dto: any = { name, @@ -153,11 +157,19 @@ export const getFixtures = async () => { if (tagName) { dto.tagName = tagName; } - return request(app.getHttpServer()) + const response = await request(app.getHttpServer()) .post(`/api/v1/projects/${projectId}/features/shapefile`) .set('Authorization', `Bearer ${token}`) .attach(`file`, __dirname + `/import-files/wetlands.zip`) .field(dto); + if (!options?.skipWaitingForFeatureToBeReady) { + expect(response.body.data.id).toBeDefined(); + await waitForFeatureToBeReady( + geoFeaturesApiRepo, + response.body.data.id, + ); + } + return response; }, WhenUploadingCustomFeatureFromCSV: async () => { await GivenProjectsPuExists(geoEntityManager, projectId); @@ -321,7 +333,7 @@ export const getFixtures = async () => { amountMin: 820348505.9774874, propertyName: null, intersection: null, - creationStatus: `done`, + creationStatus: 'created', projectId, isCustom: true, isLegacy: false, @@ -435,13 +447,8 @@ export const getFixtures = async () => { expect(feature2Amounts[2].amount).toBe(0); }, ThenFeatureAmountsPerPlanningUnitDataIsDeletedForFeatureWithGivenId: async ( - featureClassName: string, + featureId: string, ) => { - const featureId = await featuresRepository - .findOneOrFail({ - where: { featureClassName }, - }) - .then((result) => result.id); const featureAmountsPerPlanningUnitForFeature = await featureAmountsPerPlanningUnitRepo.find({ where: {