test(pipeline-tasks): task consumer unit test.

This commit is contained in:
Ivan 2021-03-04 11:43:23 +08:00
parent 64ec1433a6
commit 33b09594f5
3 changed files with 51 additions and 2 deletions

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

View File

@ -4,10 +4,10 @@ import { PipelineTasksResolver } from './pipeline-tasks.resolver';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PipelineTask } from './pipeline-task.entity';
import { Pipeline } from '../pipelines/pipeline.entity';
import { BullModule } from '@nestjs/bull';
import { ReposModule } from '../repos/repos.module';
@Module({
imports: [TypeOrmModule.forFeature([PipelineTask, Pipeline])],
imports: [TypeOrmModule.forFeature([PipelineTask, Pipeline]), ReposModule],
providers: [PipelineTasksService, PipelineTasksResolver],
})
export class PipelineTasksModule {}

View File

@ -9,5 +9,6 @@ import { ProjectsModule } from '../projects/projects.module';
@Module({
imports: [TypeOrmModule.forFeature([Project]), ConfigModule, ProjectsModule],
providers: [ReposResolver, ReposService],
exports: [ReposService],
})
export class ReposModule {}