Skip to content

Commit

Permalink
add test: no rows with amount=0 should be generated for puvspr.dat files
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Apr 23, 2024
1 parent 16645f6 commit d595602
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ describe(ComputeArea, () => {
await fixtures.ThenMinMaxAmountWasSaved();
});

it('does not include rows with amount = 0 in puvspr.dat files', async () => {
const { projectId, scenarioId } = fixtures.GivenProject();
const featureId =
fixtures.GivenFeatureWasCreatedWithSomeAmountsPerPuEqualToZero();
fixtures.GivenMinMaxAmount(featureId, undefined, undefined);

await fixtures.WhenComputing(projectId, scenarioId, featureId);

await fixtures.ThenNoPuvsprRowsWithAmountEqualToZeroShouldBeGenerated(
projectId,
featureId,
);
await fixtures.ThenMinMaxAmountWasSaved();
});

it('does not save saves amounts per planning unit when computation has already been made but saves min/max amount for the feature', async () => {
const { projectId, scenarioId } = fixtures.GivenProject();
const featureId = fixtures.GivenNoComputationHasBeenSaved();
Expand Down Expand Up @@ -111,6 +126,7 @@ const getFixtures = async () => {
sandbox.get(FeatureAmountsPerPlanningUnitRepository);

const expectedPuid = v4();
const expectedPuidWithAmountEqualToZero = v4();
const expectedAmount = 20;
return {
GivenProject: () => {
Expand Down Expand Up @@ -146,6 +162,27 @@ const getFixtures = async () => {

return featureId;
},
GivenFeatureWasCreatedWithSomeAmountsPerPuEqualToZero: () => {
const featureId = v4();
computeMarxanAmountPerPlanningUnitMock.mockImplementation(async () => {
return [
{
featureId,
projectPuId: expectedPuid,
amount: expectedAmount,
puId: 1,
},
{
featureId,
projectPuId: expectedPuidWithAmountEqualToZero,
amount: 0,
puId: 2,
},
];
});

return featureId;
},
GivenComputationAlreadySaved: (projectId: string, featureId: string) => {
featureAmountsPerPlanningUnitRepo.memory[projectId] = [
{ featureId, amount: 42, projectPuId: v4() },
Expand Down Expand Up @@ -177,6 +214,29 @@ const getFixtures = async () => {
featureId,
});
},
ThenNoPuvsprRowsWithAmountEqualToZeroShouldBeGenerated: async (
projectId: string,
featureId: string,
) => {
const savedCalculations =
await featureAmountsPerPlanningUnitRepo.getAmountPerPlanningUnitAndFeature(
projectId,
[featureId],
);

expect(savedCalculations).toBeDefined();
expect(savedCalculations[0]).toEqual({
amount: expectedAmount,
projectPuId: expectedPuid,
featureId,
});
expect(savedCalculations).not.toContain({
amount: 0,
projectPuId: expectedPuidWithAmountEqualToZero,
featureId,
});
expect(savedCalculations.length).toBe(1);
},
ThenComputationsWasNotDone: async () => {
expect(computeMarxanAmountPerPlanningUnitMock).not.toHaveBeenCalled();
},
Expand Down

0 comments on commit d595602

Please sign in to comment.