From 4ee6f564011e9aa86e2e45a05dce88e23a4a7cae Mon Sep 17 00:00:00 2001 From: Yulia Belyakova Date: Thu, 16 Feb 2023 13:40:55 +0100 Subject: [PATCH] Add chart level test --- .../impact/impact-chart/chart-levels.spec.ts | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 api/test/e2e/impact/impact-chart/chart-levels.spec.ts diff --git a/api/test/e2e/impact/impact-chart/chart-levels.spec.ts b/api/test/e2e/impact/impact-chart/chart-levels.spec.ts new file mode 100644 index 0000000000..fcb727c5bf --- /dev/null +++ b/api/test/e2e/impact/impact-chart/chart-levels.spec.ts @@ -0,0 +1,109 @@ +import { HttpStatus } from '@nestjs/common'; +import * as request from 'supertest'; +import ApplicationManager, { + TestApplication, +} from '../../../utils/application-manager'; +import { setupTestUser } from '../../../utils/userAuth'; +import { clearTestDataFromDatabase } from '../../../utils/database-test-helper'; +import { Indicator } from 'modules/indicators/indicator.entity'; +import { DataSource } from 'typeorm'; +import { createChartLevelsPreconditions } from '../mocks/chart-levels-preconditions/chart-levels.preconditions'; + +describe('Impact Chart (Ranking) Test Suite (e2e) with requested levels', () => { + let testApplication: TestApplication; + let jwtToken: string; + let dataSource: DataSource; + let indicator: Indicator; + + beforeAll(async () => { + testApplication = await ApplicationManager.init(); + + dataSource = testApplication.get(DataSource); + + ({ jwtToken } = await setupTestUser(testApplication)); + + indicator = await createChartLevelsPreconditions(); + }); + + afterAll(async () => { + await clearTestDataFromDatabase(dataSource); + await testApplication.close(); + }); + + test( + 'When I query a Impact Chart grouped by region ' + + 'And do not specify level' + + 'Then I should get response structure starting from the highest level (country) ', + async () => { + const response = await request(testApplication.getHttpServer()) + .get('/api/v1/impact/ranking') + .set('Authorization', `Bearer ${jwtToken}`) + .query({ + 'indicatorIds[]': [indicator.id], + endYear: 2020, + startYear: 2020, + groupBy: 'region', + maxRankingEntities: 4, + sort: 'DES', + }) + .expect(HttpStatus.OK); + + expect(response.body.impactTable[0].rows.length).toBe(1); + expect(response.body.impactTable[0].rows[0].name).toBe('Country'); + expect(response.body.impactTable[0].rows[0].values[0].value).toBe(7000); + }, + ); + + test( + 'When I query a Impact Chart grouped by region ' + + 'And request data for admin regions of level 2' + + 'Then I should get response structure in accordance with requested level (province) ', + async () => { + const response = await request(testApplication.getHttpServer()) + .get('/api/v1/impact/ranking') + .set('Authorization', `Bearer ${jwtToken}`) + .query({ + 'indicatorIds[]': [indicator.id], + endYear: 2020, + startYear: 2020, + groupBy: 'region', + level: 2, + maxRankingEntities: 4, + sort: 'DES', + }) + .expect(HttpStatus.OK); + + expect(response.body.impactTable[0].rows.length).toBe(3); + expect(response.body.impactTable[0].rows[0].name).toBe('Province 3'); + expect(response.body.impactTable[0].rows[0].values[0].value).toBe(3000); + }, + ); + + test( + 'When I query a Impact Chart grouped by region ' + + 'And request data for admin regions of level 3' + + 'Then I should get response structure in accordance with requested level (municipality) ', + async () => { + const response = await request(testApplication.getHttpServer()) + .get('/api/v1/impact/ranking') + .set('Authorization', `Bearer ${jwtToken}`) + .query({ + 'indicatorIds[]': [indicator.id], + endYear: 2020, + startYear: 2020, + groupBy: 'region', + level: 3, + maxRankingEntities: 5, + sort: 'DES', + }) + .expect(HttpStatus.OK); + + expect(response.body.impactTable[0].rows.length).toBe(5); + expect(response.body.impactTable[0].rows[0].name).toBe('Municipality 1'); + expect(response.body.impactTable[0].rows[0].values[0].value).toBe(1000); + expect( + response.body.impactTable[0].others.aggregatedValues[0].value, + ).toBe(2000); + }, + ); +});