Changing unit tests to use more mocked modules
This commit is contained in:
parent
c09532f89a
commit
51080310d8
1 changed files with 19 additions and 35 deletions
|
|
@ -1,11 +1,7 @@
|
||||||
import { getQueueToken } from '@nestjs/bull'
|
import { getQueueToken } from '@nestjs/bull'
|
||||||
import { ConfigModule } from '@nestjs/config'
|
|
||||||
import { Test, TestingModule } from '@nestjs/testing'
|
import { Test, TestingModule } from '@nestjs/testing'
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm'
|
|
||||||
|
|
||||||
import { LoggerModule } from '../../../src/logger/module'
|
|
||||||
import { LoggerService } from '../../../src/logger/service.logger'
|
import { LoggerService } from '../../../src/logger/service.logger'
|
||||||
import { NtfyModule } from '../../../src/ntfy/module'
|
|
||||||
import { NtfyProvider } from '../../../src/ntfy/provider'
|
import { NtfyProvider } from '../../../src/ntfy/provider'
|
||||||
import {
|
import {
|
||||||
RESERVATIONS_QUEUE_NAME,
|
RESERVATIONS_QUEUE_NAME,
|
||||||
|
|
@ -15,12 +11,8 @@ import {
|
||||||
DAILY_RESERVATIONS_ATTEMPTS,
|
DAILY_RESERVATIONS_ATTEMPTS,
|
||||||
ReservationsCronService,
|
ReservationsCronService,
|
||||||
} from '../../../src/reservations/cron'
|
} from '../../../src/reservations/cron'
|
||||||
import { Reservation } from '../../../src/reservations/entity'
|
|
||||||
import { ReservationsModule } from '../../../src/reservations/module'
|
|
||||||
import { ReservationsService } from '../../../src/reservations/service'
|
import { ReservationsService } from '../../../src/reservations/service'
|
||||||
import { BaanReserverenService } from '../../../src/runner/baanreserveren/service'
|
import { BaanReserverenService } from '../../../src/runner/baanreserveren/service'
|
||||||
import { RunnerModule } from '../../../src/runner/module'
|
|
||||||
import config from '../../config'
|
|
||||||
|
|
||||||
describe('reservations.cron', () => {
|
describe('reservations.cron', () => {
|
||||||
let module: TestingModule
|
let module: TestingModule
|
||||||
|
|
@ -28,22 +20,25 @@ describe('reservations.cron', () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
module = await Test.createTestingModule({
|
module = await Test.createTestingModule({
|
||||||
imports: [
|
providers: [
|
||||||
ReservationsModule,
|
ReservationsCronService,
|
||||||
RunnerModule,
|
{ provide: BaanReserverenService, useValue: { warmup: jest.fn() } },
|
||||||
NtfyModule,
|
{ provide: LoggerService, useValue: { debug: jest.fn() } },
|
||||||
LoggerModule,
|
{
|
||||||
ConfigModule.forRoot({
|
provide: getQueueToken(RESERVATIONS_QUEUE_NAME),
|
||||||
isGlobal: true,
|
useValue: { addBulk: jest.fn(), process: jest.fn() },
|
||||||
ignoreEnvFile: true,
|
},
|
||||||
ignoreEnvVars: true,
|
{
|
||||||
load: [() => config],
|
provide: ReservationsService,
|
||||||
}),
|
useValue: { getSchedulable: jest.fn() },
|
||||||
TypeOrmModule.forRoot({
|
},
|
||||||
type: 'sqlite',
|
{
|
||||||
database: ':memory:',
|
provide: NtfyProvider,
|
||||||
entities: [Reservation],
|
useValue: {
|
||||||
}),
|
sendCronStartNotification: jest.fn(),
|
||||||
|
sendCronStopNotification: jest.fn(),
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}).compile()
|
}).compile()
|
||||||
|
|
||||||
|
|
@ -55,17 +50,6 @@ describe('reservations.cron', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('handleDailyReservations', () => {
|
describe('handleDailyReservations', () => {
|
||||||
beforeEach(() => {
|
|
||||||
jest.spyOn(
|
|
||||||
module.get<NtfyProvider>(NtfyProvider),
|
|
||||||
'sendCronStartNotification',
|
|
||||||
)
|
|
||||||
jest.spyOn(
|
|
||||||
module.get<NtfyProvider>(NtfyProvider),
|
|
||||||
'sendCronStopNotification',
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('has scheduleable reservations', () => {
|
describe('has scheduleable reservations', () => {
|
||||||
const stubbedReservation = { id: 'abc-123' }
|
const stubbedReservation = { id: 'abc-123' }
|
||||||
let warmupSpy: jest.SpyInstance
|
let warmupSpy: jest.SpyInstance
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue