Skip to content

Commit

Permalink
spec(marxan-run): baseground for e2e spec of marxan run
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajowy committed Jul 7, 2021
1 parent b5a6fe3 commit 8e1d9ca
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PromiseType } from 'utility-types';
import { getFixtures } from './fixtures';

let fixtures: PromiseType<ReturnType<typeof getFixtures>>;

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

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

describe(`Marxan run`, () => {
beforeAll(async () => {
await fixtures.GivenUserIsLoggedIn();
await fixtures.GivenProjectOrganizationExists();
await fixtures.GivenScenarioExists(`Mouse`);
await fixtures.GivenCostSurfaceTemplateFilled();
await fixtures.WhenMarxanExecutionIsRequested();
await fixtures.WhenMarxanExecutionIsCompleted();
await fixtures.ThenResultsAreAvailable();
});

it(`should work in near future`, () => {
expect(true).toBeTruthy();
});
});
66 changes: 66 additions & 0 deletions api/apps/api/test/business-critical/marxan-run/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { bootstrapApplication } from '../../utils/api-application';
import { GivenUserIsLoggedIn } from '../../steps/given-user-is-logged-in';
import { GivenProjectExists } from '../../steps/given-project';
import { GivenScenarioExists } from '../../steps/given-scenario-exists';
import { ScenarioType } from '@marxan-api/modules/scenarios/scenario.api.entity';
import { ScenariosTestUtils } from '../../utils/scenarios.test.utils';

export const getFixtures = async () => {
const app: INestApplication = await bootstrapApplication();
const cleanups: (() => Promise<void>)[] = [];

let authToken: string;
let project: string;
let scenario: string;

return {
GivenUserIsLoggedIn: async () => {
authToken = await GivenUserIsLoggedIn(app);
},
GivenProjectOrganizationExists: async () => {
const organizationProject = await GivenProjectExists(app, authToken, {
countryCode: 'AGO',
adminAreaLevel1Id: 'AGO.15_1',
adminAreaLevel2Id: 'AGO.15.4_1',
});

project = organizationProject.projectId;
cleanups.push(organizationProject.cleanup);
},
GivenScenarioExists: async (name: string) => {
scenario = (
await GivenScenarioExists(app, project, authToken, {
name,
type: ScenarioType.marxan,
})
).id;
cleanups.push(() =>
ScenariosTestUtils.deleteScenario(app, authToken, scenario),
);
},
GivenCostSurfaceTemplateFilled: async () => {
const template = await request(app.getHttpServer())
.get(`/api/v1/scenarios/${scenario}/cost-surface/shapefile-template`)
.set('Authorization', `Bearer ${authToken}`);
console.log(template.body);
},
WhenMarxanExecutionIsRequested: async () => {
// TODO currently not implemented yet: 501
await request(app.getHttpServer())
.post(`/api/v1/scenarios/${scenario}/marxan`)
.set('Authorization', `Bearer ${authToken}`);
},
WhenMarxanExecutionIsCompleted: async () => {
return void 0;
},
ThenResultsAreAvailable: async () => {
return void 0;
},
cleanup: async () => {
await Promise.all(cleanups.map((c) => c()));
await app.close();
},
};
};
7 changes: 6 additions & 1 deletion api/apps/api/test/steps/given-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { E2E_CONFIG } from '../e2e.config';
export const GivenProjectExists = async (
app: INestApplication,
jwt: string,
adminArea?: {
countryCode?: string;
adminAreaLevel1Id?: string;
adminAreaLevel2Id?: string;
},
): Promise<{
projectId: string;
organizationId: string;
Expand All @@ -20,7 +25,7 @@ export const GivenProjectExists = async (
).data.id;
const projectId = (
await ProjectsTestUtils.createProject(app, jwt, {
...E2E_CONFIG.projects.valid.minimal(),
...E2E_CONFIG.projects.valid.minimalInGivenAdminArea(adminArea),
organizationId,
})
).data.id;
Expand Down
2 changes: 2 additions & 0 deletions api/apps/api/test/steps/given-scenario-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export const GivenScenarioExists = async (
app: INestApplication,
projectId: string,
jwtToken: string,
options?: Partial<CreateScenarioDTO>,
) => {
const createScenarioDTO: Partial<CreateScenarioDTO> = {
...E2E_CONFIG.scenarios.valid.minimal(),
...options,
projectId,
};
return (
Expand Down

0 comments on commit 8e1d9ca

Please sign in to comment.