UnitTests: Add appConfigMock

This is necessary as the Logger needs this config for the loglevel.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-04-14 00:19:09 +02:00
parent a87408009d
commit 0ef9a338f3
4 changed files with 39 additions and 4 deletions

View file

@ -12,6 +12,8 @@ import { Identity } from '../../../users/identity.entity';
import { User } from '../../../users/user.entity'; import { User } from '../../../users/user.entity';
import { AuthToken } from '../../../auth/auth-token.entity'; import { AuthToken } from '../../../auth/auth-token.entity';
import { AuthModule } from '../../../auth/auth.module'; import { AuthModule } from '../../../auth/auth.module';
import { ConfigModule } from '@nestjs/config';
import appConfigMock from '../../../config/mock/app.config.mock';
describe('TokensController', () => { describe('TokensController', () => {
let controller: TokensController; let controller: TokensController;
@ -19,7 +21,14 @@ describe('TokensController', () => {
beforeEach(async () => { beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({ const module: TestingModule = await Test.createTestingModule({
controllers: [TokensController], controllers: [TokensController],
imports: [LoggerModule, AuthModule], imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [appConfigMock],
}),
LoggerModule,
AuthModule,
],
}) })
.overrideProvider(getRepositoryToken(User)) .overrideProvider(getRepositoryToken(User))
.useValue({}) .useValue({})

View file

@ -21,6 +21,8 @@ import { LoggerModule } from '../logger/logger.module';
import { AuthToken } from './auth-token.entity'; import { AuthToken } from './auth-token.entity';
import { NotInDBError, TokenNotValidError } from '../errors/errors'; import { NotInDBError, TokenNotValidError } from '../errors/errors';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { ConfigModule } from '@nestjs/config';
import appConfigMock from '../config/mock/app.config.mock';
describe('AuthService', () => { describe('AuthService', () => {
let service: AuthService; let service: AuthService;
@ -38,7 +40,15 @@ describe('AuthService', () => {
useClass: Repository, useClass: Repository,
}, },
], ],
imports: [PassportModule, UsersModule, LoggerModule], imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [appConfigMock],
}),
PassportModule,
UsersModule,
LoggerModule,
],
}) })
.overrideProvider(getRepositoryToken(Identity)) .overrideProvider(getRepositoryToken(Identity))
.useValue({}) .useValue({})

View file

@ -11,6 +11,8 @@ import { Repository } from 'typeorm';
import { Group } from './group.entity'; import { Group } from './group.entity';
import { NotInDBError } from '../errors/errors'; import { NotInDBError } from '../errors/errors';
import { LoggerModule } from '../logger/logger.module'; import { LoggerModule } from '../logger/logger.module';
import { ConfigModule } from '@nestjs/config';
import appConfigMock from '../config/mock/app.config.mock';
describe('GroupsService', () => { describe('GroupsService', () => {
let service: GroupsService; let service: GroupsService;
@ -26,7 +28,13 @@ describe('GroupsService', () => {
useClass: Repository, useClass: Repository,
}, },
], ],
imports: [LoggerModule], imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [appConfigMock],
}),
LoggerModule,
],
}).compile(); }).compile();
service = module.get<GroupsService>(GroupsService); service = module.get<GroupsService>(GroupsService);

View file

@ -9,6 +9,8 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { LoggerModule } from '../logger/logger.module'; import { LoggerModule } from '../logger/logger.module';
import { User } from './user.entity'; import { User } from './user.entity';
import { UsersService } from './users.service'; import { UsersService } from './users.service';
import { ConfigModule } from '@nestjs/config';
import appConfigMock from '../config/mock/app.config.mock';
describe('UsersService', () => { describe('UsersService', () => {
let service: UsersService; let service: UsersService;
@ -22,7 +24,13 @@ describe('UsersService', () => {
useValue: {}, useValue: {},
}, },
], ],
imports: [LoggerModule], imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [appConfigMock],
}),
LoggerModule,
],
}) })
.overrideProvider(getRepositoryToken(User)) .overrideProvider(getRepositoryToken(User))
.useValue({}) .useValue({})