-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
api/apps/api/test/project/create-project-wdpa-area-filter.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
}); |
85 changes: 85 additions & 0 deletions
85
api/apps/api/test/project/create-project-wdpa-area-filter.fixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
}, | ||
}; | ||
}; |