From e28c9228bc7796bf8dd6524b8841feb33940935b Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Tue, 6 Dec 2022 18:10:34 +0200 Subject: [PATCH] add a test --- package.json | 5 +- ...egister-industry-change-application.dto.ts | 2 +- .../industry-change-application.spec.ts | 108 ++++++++++++++++++ 3 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/industry-change-application/industry-change-application.spec.ts diff --git a/package.json b/package.json index d8c8a63..c4dc829 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,9 @@ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "^src/(.*)$": "/$1" + } } } diff --git a/src/industry-change-application/dtos/register-industry-change-application.dto.ts b/src/industry-change-application/dtos/register-industry-change-application.dto.ts index 75eabe6..9b3cfb5 100644 --- a/src/industry-change-application/dtos/register-industry-change-application.dto.ts +++ b/src/industry-change-application/dtos/register-industry-change-application.dto.ts @@ -26,5 +26,5 @@ export class RegisterIndustryChangeApplicationDto { @IsOptional() @IsString() @ValidateIf((o) => o.willWorkInPhysicalJurisdiction === true) - regulatoryElectionSub: string; + regulatoryElectionSub?: string; } diff --git a/src/industry-change-application/industry-change-application.spec.ts b/src/industry-change-application/industry-change-application.spec.ts new file mode 100644 index 0000000..3f82480 --- /dev/null +++ b/src/industry-change-application/industry-change-application.spec.ts @@ -0,0 +1,108 @@ +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { MongooseModule } from '@nestjs/mongoose'; +import { Test, TestingModule } from '@nestjs/testing'; +import { ResidentModule } from 'src/resident/resident.module'; +import { Industry } from '../enums/industry.enum'; +import { RegulatoryElection } from '../enums/regulatory-election.enums'; +import { IndustryChangeApplicationController } from './industry-change-application.controller'; +import { IndustryChangeApplicationService } from './industry-change-application.service'; +import { Decision, DecisionSchema } from './schemas/Decision.schema'; +import { + ICAInformation, + ICAInformationSchema, +} from './schemas/ICAInformation.schema'; +import { + IndustryChangeApplication, + IndustryChangeApplicationSchema, +} from './schemas/IndustryChangeApplication.schema'; + +describe('IndustryChangeApplicationController', () => { + let app: TestingModule; + + beforeAll(async () => { + app = await Test.createTestingModule({ + imports: [ + ConfigModule.forRoot(), + MongooseModule.forRootAsync({ + imports: [ConfigModule], + useFactory: async (configService: ConfigService) => ({ + uri: configService.get('MONGODB_URI'), + }), + inject: [ConfigService], + }), + MongooseModule.forFeature([ + { + name: Decision.name, + schema: DecisionSchema, + }, + { + name: ICAInformation.name, + schema: ICAInformationSchema, + }, + { + name: IndustryChangeApplication.name, + schema: IndustryChangeApplicationSchema, + }, + ]), + ResidentModule, + ], + controllers: [IndustryChangeApplicationController], + providers: [IndustryChangeApplicationService], + }).compile(); + }); + + describe('flow', () => { + let docID: string | undefined; + it('should create a new application', async () => { + const appController = app.get(IndustryChangeApplicationController); + const createData = (await appController.create( + { + residentSub: 'f26d49bd-73aa-4e9c-b793-a367e1315b7d', + willWorkInPhysicalJurisdiction: true, + industry: Industry.WASTE_MANAGEMENT, + regulatoryElection: RegulatoryElection.ESTONIA, + }, + 'auth token goes here', + )) as any; + expect(createData.status).toBe('IN_REVIEW'); + docID = createData.id; + }); + + it('should find the application in the list', async () => { + const appController = app.get(IndustryChangeApplicationController); + const getter = (await appController.getList({ + residentSub: 'f26d49bd-73aa-4e9c-b793-a367e1315b7d', + })) as any; + + expect(getter).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + id: docID, + }), + ]), + ); + }); + + it('should request the application by id', async () => { + const appController = app.get(IndustryChangeApplicationController); + const getter = (await appController.getSingle(docID)) as any; + expect(getter.status).toBe('IN_REVIEW'); + expect(getter.id).toBe(docID); + }); + + it('should delete the application', async () => { + const appController = app.get(IndustryChangeApplicationController); + const getter = (await appController.delete( + docID, + 'auth token goes here', + )) as any; + expect(getter.objectStatus).toBe('DELETED'); + }); + + it('should request the application and ensure it is deleted', async () => { + const appController = app.get(IndustryChangeApplicationController); + const getter = (await appController.getSingle(docID)) as any; + expect(getter.objectStatus).toBe('DELETED'); + }); + }); +});