feat-pipelines #1

Merged
Ivan merged 25 commits from feat-pipelines into master 2021-03-24 20:50:41 +08:00
3 changed files with 51 additions and 2 deletions
Showing only changes of commit 33b09594f5 - Show all commits

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 {}