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'); }); }); });