Skip to content

Commit

Permalink
wait for feature to be ready after uploading a shapefile
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Feb 16, 2024
1 parent cdaf36a commit d85eedf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions api/apps/api/test/upload-feature/upload-feature.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -143,10 +145,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,
);
});
23 changes: 15 additions & 8 deletions api/apps/api/test/upload-feature/upload-feature.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -145,6 +146,9 @@ export const getFixtures = async () => {
name: string,
description: string,
tagName?: string,
options?: {
skipWaitingForFeatureToBeReady?: boolean;
},
) => {
const dto: any = {
name,
Expand All @@ -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);
Expand Down Expand Up @@ -321,7 +333,7 @@ export const getFixtures = async () => {
amountMin: 820348505.9774874,
propertyName: null,
intersection: null,
creationStatus: `done`,
creationStatus: 'created',
projectId,
isCustom: true,
isLegacy: false,
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit d85eedf

Please sign in to comment.