add a test

This commit is contained in:
Evert Prants 2022-12-06 18:10:34 +02:00
parent b8ff56847a
commit e28c9228bc
3 changed files with 113 additions and 2 deletions

View File

@ -70,6 +70,9 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
}
}

View File

@ -26,5 +26,5 @@ export class RegisterIndustryChangeApplicationDto {
@IsOptional()
@IsString()
@ValidateIf((o) => o.willWorkInPhysicalJurisdiction === true)
regulatoryElectionSub: string;
regulatoryElectionSub?: string;
}

View File

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