Skip to content

Commit

Permalink
scenario comparison tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Dec 20, 2023
1 parent ad443af commit 98d9d7f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
6 changes: 3 additions & 3 deletions api/src/modules/impact/impact-report.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ImpactReportController {
})
@UseInterceptors(SetScenarioIdsInterceptor)
@Get('table/report')
async getImpactTable(
async getImpactReport(
@Query(ValidationPipe) impactTableDto: GetImpactTableDto,
@Res() res: Response,
): Promise<void> {
Expand Down Expand Up @@ -63,7 +63,7 @@ export class ImpactReportController {
})
@UseInterceptors(SetScenarioIdsInterceptor)
@Get('compare/scenario/vs/actual/report')
async getActualVsScenarioImpactTable(
async getActualVsScenarioImpactReport(
@Query(ValidationPipe)
actualVsScenarioImpactTableDto: GetActualVsScenarioImpactTableDto,
@Res() res: Response,
Expand Down Expand Up @@ -94,7 +94,7 @@ export class ImpactReportController {
})
@UseInterceptors(SetScenarioIdsInterceptor)
@Get('compare/scenario/vs/scenario/report')
async getTwoScenariosImpactTable(
async getTwoScenariosImpacReport(
@Query(ValidationPipe)
scenarioVsScenarioImpactTableDto: GetScenarioVsScenarioImpactTableDto,
@Res() res: Response,
Expand Down
23 changes: 18 additions & 5 deletions api/test/e2e/impact/impact-reports/impact-reports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import ApplicationManager, {
} from '../../../utils/application-manager';
import { DataSource } from 'typeorm';
import { setupTestUser } from '../../../utils/userAuth';
import {
clearEntityTables,
clearTestDataFromDatabase,
} from '../../../utils/database-test-helper';
import { clearTestDataFromDatabase } from '../../../utils/database-test-helper';
import { Indicator } from '../../../../src/modules/indicators/indicator.entity';

describe('Impact Reports', () => {
Expand Down Expand Up @@ -60,5 +57,21 @@ describe('Impact Reports', () => {
isActualVsScenario: true,
});
});
it('should create a scenario vs scenario impact report', async () => {});
it('should create a scenario vs scenario impact report', async () => {
const { baseScenario, comparedScenario, indicator } =
await fixtures.GivenTwoScenarios();
const response = await fixtures.WhenIRequestAScenarioVsScenarioImpactReport(
{
app: testApplication,
jwtToken,
baseScenarioId: baseScenario.id,
comparedScenarioId: comparedScenario.id,
indicatorIds: [indicator.id],
},
);
await fixtures.ThenIShouldGetAnImpactReportAboutProvidedFilters(response, {
indicators: [indicator],
isScenarioVsScenario: true,
});
});
});
33 changes: 33 additions & 0 deletions api/test/e2e/impact/impact-reports/impactReportFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Material } from '../../../../src/modules/materials/material.entity';
import { Scenario } from 'modules/scenarios/scenario.entity';
import { createNewCoefficientsInterventionPreconditions } from '../mocks/actual-vs-scenario-preconditions/new-coefficients-intervention.preconditions';
import { ScenarioIntervention } from '../../../../src/modules/scenario-interventions/scenario-intervention.entity';
import { createSameMaterialTwoScenariosPreconditions } from '../mocks/scenario-vs-scenario-preconditions/same-materials-scenarios.preconditions';

export const impactReportFixtures = () => ({
GivenSourcingLocationWithImpact: async () => {
Expand Down Expand Up @@ -105,6 +106,19 @@ export const impactReportFixtures = () => ({
scenarioIntervention,
};
},
GivenTwoScenarios: async (): Promise<any> => {
const {
newScenarioChangeSupplier: baseScenario,
newScenarioChangeMaterial: comparedScenario,
indicator,
} = await createSameMaterialTwoScenariosPreconditions();

return {
baseScenario,
comparedScenario,
indicator,
};
},

WhenIRequestAnImpactReport: (options: {
app: TestApplication;
Expand Down Expand Up @@ -138,6 +152,25 @@ export const impactReportFixtures = () => ({
comparedScenarioId: options.comparedScenarioId,
});
},
WhenIRequestAScenarioVsScenarioImpactReport: (options: {
app: TestApplication;
jwtToken: string;
indicatorIds: string[];
baseScenarioId: string;
comparedScenarioId: string;
}) => {
return request(options.app.getHttpServer())
.get('/api/v1/impact/compare/scenario/vs/scenario/report')
.set('Authorization', `Bearer ${options.jwtToken}`)
.query({
'indicatorIds[]': [...options.indicatorIds],
startYear: 2010,
endYear: 2027,
groupBy: 'material',
baseScenarioId: options.baseScenarioId,
comparedScenarioId: options.comparedScenarioId,
});
},

ThenIShouldGetAnImpactReportAboutProvidedFilters: (
response: request.Response,
Expand Down
6 changes: 3 additions & 3 deletions api/test/e2e/impact/impact-table/scenario-vs-scenario.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
getSameMaterialScenarioComparisonResponse,
getScenarioComparisonResponseBySupplier,
} from '../mocks/scenario-vs-scenario-responses/same-materials-scenarios.reponse';
import { createSameMaterialScenariosPreconditions } from '../mocks/scenario-vs-scenario-preconditions/same-materials-scenarios.preconditions';
import { createSameMaterialTwoScenariosPreconditions } from '../mocks/scenario-vs-scenario-preconditions/same-materials-scenarios.preconditions';
import { DataSource } from 'typeorm';
import { createImpactTableSortingPreconditions } from '../mocks/sorting.preconditions';
import { ImpactTableRows } from 'modules/impact/dto/response-impact-table.dto';
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('Scenario VS Scenario Impact Table test suite (e2e)', () => {
newScenarioChangeSupplier: Scenario;
newScenarioChangeMaterial: Scenario;
indicator: Indicator;
} = await createSameMaterialScenariosPreconditions();
} = await createSameMaterialTwoScenariosPreconditions();

const responseGroupByMaterial = await request(
testApplication.getHttpServer(),
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('Scenario VS Scenario Impact Table test suite (e2e)', () => {
newScenarioChangeSupplier: Scenario;
newScenarioChangeMaterial: Scenario;
indicator: Indicator;
} = await createSameMaterialScenariosPreconditions();
} = await createSameMaterialTwoScenariosPreconditions();

const response = await request(testApplication.getHttpServer())
.get('/api/v1/impact/compare/scenario/vs/scenario')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '../../../../entity-mocks';
import { INDICATOR_NAME_CODES } from 'modules/indicators/indicator.entity';

export async function createSameMaterialScenariosPreconditions(): Promise<{
export async function createSameMaterialTwoScenariosPreconditions(): Promise<{
indicator: Indicator;
newScenarioChangeSupplier: Scenario;
newScenarioChangeMaterial: Scenario;
Expand All @@ -43,6 +43,7 @@ export async function createSameMaterialScenariosPreconditions(): Promise<{
name: 'Deforestation',
unit,
nameCode: INDICATOR_NAME_CODES.DF_SLUC,
shortName: 'Deforestation',
});

const textile: Material = await createMaterial({ name: 'Textile' });
Expand Down

0 comments on commit 98d9d7f

Please sign in to comment.