From fc079e852621715bb06fa8c0fc4ea37b4322dc11 Mon Sep 17 00:00:00 2001 From: alexeh Date: Wed, 20 Dec 2023 14:46:33 +0300 Subject: [PATCH] scenario comparison tests --- .../impact/impact-report.controller.ts | 6 ++-- .../impact-reports/impact-reports.spec.ts | 23 ++++++++++--- .../impact-reports/impactReportFixtures.ts | 33 +++++++++++++++++++ .../impact-table/scenario-vs-scenario.spec.ts | 6 ++-- .../same-materials-scenarios.preconditions.ts | 3 +- 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/api/src/modules/impact/impact-report.controller.ts b/api/src/modules/impact/impact-report.controller.ts index ccbb2a067..9ef84f51b 100644 --- a/api/src/modules/impact/impact-report.controller.ts +++ b/api/src/modules/impact/impact-report.controller.ts @@ -35,7 +35,7 @@ export class ImpactReportController { }) @UseInterceptors(SetScenarioIdsInterceptor) @Get('table/report') - async getImpactTable( + async getImpactReport( @Query(ValidationPipe) impactTableDto: GetImpactTableDto, @Res() res: Response, ): Promise { @@ -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, @@ -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, diff --git a/api/test/e2e/impact/impact-reports/impact-reports.spec.ts b/api/test/e2e/impact/impact-reports/impact-reports.spec.ts index e5adc8e2d..2b1081718 100644 --- a/api/test/e2e/impact/impact-reports/impact-reports.spec.ts +++ b/api/test/e2e/impact/impact-reports/impact-reports.spec.ts @@ -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', () => { @@ -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, + }); + }); }); diff --git a/api/test/e2e/impact/impact-reports/impactReportFixtures.ts b/api/test/e2e/impact/impact-reports/impactReportFixtures.ts index d58b0d1eb..4737f5c38 100644 --- a/api/test/e2e/impact/impact-reports/impactReportFixtures.ts +++ b/api/test/e2e/impact/impact-reports/impactReportFixtures.ts @@ -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 () => { @@ -105,6 +106,19 @@ export const impactReportFixtures = () => ({ scenarioIntervention, }; }, + GivenTwoScenarios: async (): Promise => { + const { + newScenarioChangeSupplier: baseScenario, + newScenarioChangeMaterial: comparedScenario, + indicator, + } = await createSameMaterialTwoScenariosPreconditions(); + + return { + baseScenario, + comparedScenario, + indicator, + }; + }, WhenIRequestAnImpactReport: (options: { app: TestApplication; @@ -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, diff --git a/api/test/e2e/impact/impact-table/scenario-vs-scenario.spec.ts b/api/test/e2e/impact/impact-table/scenario-vs-scenario.spec.ts index a6727296d..3840feca5 100644 --- a/api/test/e2e/impact/impact-table/scenario-vs-scenario.spec.ts +++ b/api/test/e2e/impact/impact-table/scenario-vs-scenario.spec.ts @@ -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'; @@ -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(), @@ -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') diff --git a/api/test/e2e/impact/mocks/scenario-vs-scenario-preconditions/same-materials-scenarios.preconditions.ts b/api/test/e2e/impact/mocks/scenario-vs-scenario-preconditions/same-materials-scenarios.preconditions.ts index a418e1fd3..3e04ed38b 100644 --- a/api/test/e2e/impact/mocks/scenario-vs-scenario-preconditions/same-materials-scenarios.preconditions.ts +++ b/api/test/e2e/impact/mocks/scenario-vs-scenario-preconditions/same-materials-scenarios.preconditions.ts @@ -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; @@ -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' });