Skip to content

Commit

Permalink
cast test values to INDICATOR_NAME_CODES
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Sep 4, 2023
1 parent 62d7620 commit 8fd8b6e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
7 changes: 5 additions & 2 deletions api/test/e2e/h3-data/h3-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
createSourcingRecord,
} from '../../entity-mocks';
import { H3Data } from 'modules/h3-data/h3-data.entity';
import { Indicator } from 'modules/indicators/indicator.entity';
import {
Indicator,
INDICATOR_NAME_CODES,
} from 'modules/indicators/indicator.entity';
import { MATERIAL_TO_H3_TYPE } from 'modules/materials/material-to-h3.entity';
import { MaterialsToH3sService } from 'modules/materials/materials-to-h3s.service';
import { h3BasicFixture } from './mocks/h3-fixtures';
Expand Down Expand Up @@ -320,7 +323,7 @@ describe('H3-Data Module (e2e) - Get H3 data', () => {
test('Given there is material H3 data, When I query available years providing a indicator id, then I should get all available years for that indicator', async () => {
const years = [2001, 2001, 2002, 2003, 2007];
const savedIndicator: Indicator = await createIndicator({
nameCode: 'GAMMA_RADIATION',
nameCode: 'GAMMA_RADIATION' as INDICATOR_NAME_CODES,
});
const fakeH3MasterData: Array<Partial<H3Data>> = [];
for await (const year of years) {
Expand Down
5 changes: 3 additions & 2 deletions api/test/e2e/h3-data/mocks/h3-data.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DataSource } from 'typeorm';
import { H3Data } from 'modules/h3-data/h3-data.entity';
import { snakeCase, camelCase } from 'typeorm/util/StringUtils';
import { INDICATOR_NAME_CODES } from '../../../../src/modules/indicators/indicator.entity';

export const h3DataMock = async (
dataSource: DataSource,
Expand Down Expand Up @@ -58,5 +59,5 @@ export const dropH3DataMock = async (
export const createRandomNamesForH3TableAndColumns = (): string =>
(Math.random() + 1).toString(36).substring(2);

export const createRandomIndicatorNameCode = (): string =>
`${Math.random() + 1}_${Math.random() + 1}`;
export const createRandomIndicatorNameCode = (): INDICATOR_NAME_CODES =>
`${Math.random() + 1}_${Math.random() + 1}` as INDICATOR_NAME_CODES;
5 changes: 3 additions & 2 deletions api/test/e2e/h3-data/mocks/h3-impact-map.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Unit } from 'modules/units/unit.entity';
import { UnitConversion } from 'modules/unit-conversions/unit-conversion.entity';
import {
Indicator,
INDICATOR_NAME_CODES,
INDICATOR_STATUS,
} from 'modules/indicators/indicator.entity';
import { h3DataMock } from './h3-data.mock';
Expand Down Expand Up @@ -81,14 +82,14 @@ export const createImpactMapMockData = async (
const indicator: Indicator = new Indicator();
indicator.name = 'test indicator';
indicator.unit = unit;
indicator.nameCode = 'UWU_T';
indicator.nameCode = 'UWU_T' as INDICATOR_NAME_CODES;
await indicator.save();

const inactiveIndicator: Indicator = new Indicator();
inactiveIndicator.name = 'Inactive Indicator';
inactiveIndicator.unit = unit;
inactiveIndicator.status = INDICATOR_STATUS.INACTIVE;
inactiveIndicator.nameCode = 'INA_IN';
inactiveIndicator.nameCode = 'INA_IN' as INDICATOR_NAME_CODES;
await inactiveIndicator.save();

const harvestH3Data = await h3DataMock(dataSource, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function createTwoScenariosPreconditions(): Promise<{
name: 'Deforestation',
shortName: 'Deforestation',
unit,
nameCode: INDICATOR_NAME_CODES.DEFORESTATION,
nameCode: INDICATOR_NAME_CODES.DEFORESTATION_RISK,
});

const textile: Material = await createMaterial({ name: 'Textile' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function createMixedScenariosPreconditions(): Promise<{
const indicator: Indicator = await createIndicator({
name: 'Deforestation',
unit,
nameCode: INDICATOR_NAME_CODES.DEFORESTATION,
nameCode: INDICATOR_NAME_CODES.DEFORESTATION_RISK,
});

const textile: Material = await createMaterial({ name: 'Textile' });
Expand Down
7 changes: 5 additions & 2 deletions api/test/e2e/targets/targets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import * as request from 'supertest';
import { Target } from 'modules/targets/target.entity';
import { TargetsRepository } from 'modules/targets/targets.repository';
import { createIndicator, createTarget } from '../../entity-mocks';
import { Indicator } from 'modules/indicators/indicator.entity';
import {
Indicator,
INDICATOR_NAME_CODES,
} from 'modules/indicators/indicator.entity';
import { IndicatorRepository } from 'modules/indicators/indicator.repository';
import { clearTestDataFromDatabase } from '../../utils/database-test-helper';
import { DataSource } from 'typeorm';
Expand Down Expand Up @@ -51,7 +54,7 @@ describe('Tasks Module (e2e)', () => {
describe('Targets - Create', () => {
test('Creating a new target (happy case)', async () => {
const indicator: Indicator = await createIndicator({
nameCode: 'GAMMA_RADIATION',
nameCode: 'GAMMA_RADIATION' as INDICATOR_NAME_CODES,
});

const response = await request(testApplication.getHttpServer())
Expand Down

0 comments on commit 8fd8b6e

Please sign in to comment.