Skip to content

Commit

Permalink
add test for cleanup task
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Feb 15, 2024
1 parent df58c8d commit 41faef1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions api/apps/api/test/projects/crud/delete-project-feature.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { GeoFeatureGeometry } from '@marxan/geofeatures';
import { apiConnections } from '@marxan-api/ormconfig';
import { GivenScenarioExists } from '../../steps/given-scenario-exists';
import { DbConnections } from '@marxan-api/ormconfig.connections';
import { FeatureAmountsPerPlanningUnitEntity } from '@marxan/feature-amounts-per-planning-unit';

let fixtures: FixtureType<typeof getFixtures>;

Expand Down Expand Up @@ -134,6 +135,18 @@ describe('Project - Delete Feature', () => {
);
await fixtures.ThenGeoFeaturesIsDeleted(result, featureId);
});

test('should delete feature_amounts_per_planning_unit data related to a feature when this is deleted', async () => {
const projectId = fixtures.projectId;
const featureId = await fixtures.GivenBaseFeature(
'deletedFeature',
projectId,
);
await fixtures.WhenDeletingFeatureForProject(projectId, featureId);
await fixtures.ThenFeatureAmountsPerPlanningUnitDataIsDeletedForFeatureWithGivenId(
featureId,
);
});
});

// NOTE:
Expand All @@ -156,6 +169,8 @@ const getFixtures = async () => {
const featuresDataRepo: Repository<GeoFeatureGeometry> = app.get(
getRepositoryToken(GeoFeatureGeometry, DbConnections.geoprocessingDB),
);
const featureAmountsPerPlanningUnitRepo: Repository<FeatureAmountsPerPlanningUnitEntity> =
app.get(getRepositoryToken(FeatureAmountsPerPlanningUnitEntity));
const scenarioRepo: Repository<Scenario> = app.get(
getRepositoryToken(Scenario),
);
Expand Down Expand Up @@ -309,5 +324,17 @@ const getFixtures = async () => {
});
expect(feature).toBeNull();
},

ThenFeatureAmountsPerPlanningUnitDataIsDeletedForFeatureWithGivenId: async (
featureId: string,
) => {
const featureAmountsPerPlanningUnitForFeature =
await featureAmountsPerPlanningUnitRepo.find({
where: {
featureId,
},
});
expect(featureAmountsPerPlanningUnitForFeature).toBeUndefined();
},
};
};

0 comments on commit 41faef1

Please sign in to comment.