Skip to content

Commit

Permalink
fix(scenarios): wdpa filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajowy committed Sep 23, 2021
1 parent 385346f commit 29c901c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { FixtureType } from '@marxan/utils/tests/fixture-type';
import { getFixtures } from './create-project-wdpa-area-filter.fixtures';
import { IUCNCategory } from '@marxan/iucn';

let fixtures: FixtureType<typeof getFixtures>;

beforeEach(async () => {
fixtures = await getFixtures();
});

afterEach(async () => {
await fixtures?.cleanup();
});

test(`creating multiple projects should have different protectedAreaFilterByIds`, async () => {
const projectIdOne: string = await fixtures.WhenProjectIsCreated(`BWA`);
const scenarioIdOne: string = await fixtures.WhenScenarioIsCreated(
projectIdOne,
[IUCNCategory.NotApplicable],
);
const projectIdTwo: string = await fixtures.WhenProjectIsCreated(`ZMB`);
const scenarioIdTwo: string = await fixtures.WhenScenarioIsCreated(
projectIdTwo,
[IUCNCategory.NotReported],
);
await fixtures.ThenProtectedAreaFiltersAreDifferent(
scenarioIdOne,
scenarioIdTwo,
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { bootstrapApplication } from '../utils/api-application';
import { GivenUserIsLoggedIn } from '../steps/given-user-is-logged-in';
import { OrganizationsTestUtils } from '../utils/organizations.test.utils';
import { E2E_CONFIG } from '../e2e.config';
import { ProjectsTestUtils } from '../utils/projects.test.utils';
import { ScenariosTestUtils } from '../utils/scenarios.test.utils';
import { ScenarioType } from '@marxan-api/modules/scenarios/scenario.api.entity';
import * as request from 'supertest';
import { IUCNCategory } from '@marxan/iucn';

export const getFixtures = async () => {
const app = await bootstrapApplication();
const token = await GivenUserIsLoggedIn(app);
const organizationId = (
await OrganizationsTestUtils.createOrganization(app, token, {
...E2E_CONFIG.organizations.valid.minimal(),
name: `Org name ${Date.now()}`,
})
).data.id;
const addedProjects: string[] = [];
return {
cleanup: async () => {
await Promise.all(
addedProjects.map((id) =>
ProjectsTestUtils.deleteProject(app, token, id),
),
);
await OrganizationsTestUtils.deleteOrganization(
app,
token,
organizationId,
);
await app.close();
},
WhenProjectIsCreated: async (countryId: string) => {
const projectId = (
await ProjectsTestUtils.createProject(app, token, {
name: `Project name ${Date.now()}`,
organizationId,
metadata: {},
countryId,
})
).data.id;
addedProjects.push(projectId);
return projectId;
},
WhenScenarioIsCreated: async (
projectId: string,
categories: IUCNCategory[],
) =>
(
await ScenariosTestUtils.createScenario(app, token, {
name: `Scenario for ${projectId} ${Date.now()}`,
projectId,
type: ScenarioType.marxan,
wdpaIucnCategories: categories,
})
).data.id,
ThenProtectedAreaFiltersAreDifferent: async (
scenarioIdOne: string,
scenarioIdTwo: string,
) => {
const scenarioOneData = await request(app.getHttpServer())
.get(`/api/v1/scenarios/${scenarioIdOne}`)
.set('Authorization', `Bearer ${token}`);

const scenarioTwoData = await request(app.getHttpServer())
.get(`/api/v1/scenarios/${scenarioIdTwo}`)
.set('Authorization', `Bearer ${token}`);

expect(
scenarioOneData.body.data.attributes.protectedAreaFilterByIds.length,
).toBeGreaterThan(0);
expect(
scenarioTwoData.body.data.attributes.protectedAreaFilterByIds.length,
).toBeGreaterThan(0);

expect(
scenarioOneData.body.data.attributes.protectedAreaFilterByIds,
).not.toEqual(
scenarioTwoData.body.data.attributes.protectedAreaFilterByIds,
);
},
};
};

0 comments on commit 29c901c

Please sign in to comment.