test(pipeline-tasks): task consumer unit test.
This commit is contained in:
parent
64ec1433a6
commit
33b09594f5
48
src/pipeline-tasks/pipeline-task.consumer.spec.ts
Normal file
48
src/pipeline-tasks/pipeline-task.consumer.spec.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { Job } from 'bull';
|
||||||
|
import { PipelineUnits } from './enums/pipeline-units.enum';
|
||||||
|
import { PipelineTaskConsumer } from './pipeline-task.consumer';
|
||||||
|
import { PipelineTask } from './pipeline-task.entity';
|
||||||
|
import { PipelineTasksService } from './pipeline-tasks.service';
|
||||||
|
|
||||||
|
describe('PipelineTaskConsumer', () => {
|
||||||
|
let consumer: PipelineTaskConsumer;
|
||||||
|
let tasksService: PipelineTasksService;
|
||||||
|
const getJob = () =>
|
||||||
|
({
|
||||||
|
data: {
|
||||||
|
pipelineId: 'test',
|
||||||
|
units: [PipelineUnits.checkout, PipelineUnits.test],
|
||||||
|
},
|
||||||
|
} as Job<PipelineTask>);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: PipelineTasksService,
|
||||||
|
useValue: {
|
||||||
|
doNextTask: () => undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PipelineTaskConsumer,
|
||||||
|
],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
tasksService = module.get(PipelineTasksService);
|
||||||
|
consumer = module.get(PipelineTaskConsumer);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(consumer).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onCompleted', () => {
|
||||||
|
it('should call doNextTask()', () => {
|
||||||
|
const job = getJob();
|
||||||
|
const doNextTask = jest.spyOn(tasksService, 'doNextTask');
|
||||||
|
consumer.onCompleted(job);
|
||||||
|
expect(doNextTask).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -4,10 +4,10 @@ import { PipelineTasksResolver } from './pipeline-tasks.resolver';
|
|||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { PipelineTask } from './pipeline-task.entity';
|
import { PipelineTask } from './pipeline-task.entity';
|
||||||
import { Pipeline } from '../pipelines/pipeline.entity';
|
import { Pipeline } from '../pipelines/pipeline.entity';
|
||||||
import { BullModule } from '@nestjs/bull';
|
import { ReposModule } from '../repos/repos.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([PipelineTask, Pipeline])],
|
imports: [TypeOrmModule.forFeature([PipelineTask, Pipeline]), ReposModule],
|
||||||
providers: [PipelineTasksService, PipelineTasksResolver],
|
providers: [PipelineTasksService, PipelineTasksResolver],
|
||||||
})
|
})
|
||||||
export class PipelineTasksModule {}
|
export class PipelineTasksModule {}
|
||||||
|
@ -9,5 +9,6 @@ import { ProjectsModule } from '../projects/projects.module';
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([Project]), ConfigModule, ProjectsModule],
|
imports: [TypeOrmModule.forFeature([Project]), ConfigModule, ProjectsModule],
|
||||||
providers: [ReposResolver, ReposService],
|
providers: [ReposResolver, ReposService],
|
||||||
|
exports: [ReposService],
|
||||||
})
|
})
|
||||||
export class ReposModule {}
|
export class ReposModule {}
|
||||||
|
Loading…
Reference in New Issue
Block a user