refactor(pipeline, repo): rabbitmq

This commit is contained in:
Ivan Li
2021-05-30 22:36:06 +08:00
parent b3a2b11db9
commit 3ee41ece67
35 changed files with 287 additions and 1227 deletions

View File

@ -2,18 +2,14 @@ import { Test, TestingModule } from '@nestjs/testing';
import { PipelinesService } from './pipelines.service';
import { Pipeline } from './pipeline.entity';
import { getRepositoryToken } from '@nestjs/typeorm';
import { getQueueToken } from '@nestjs/bull';
import { LIST_LOGS_TASK } from '../repos/repos.constants';
import { Repository } from 'typeorm';
import { Project } from '../projects/project.entity';
import { Job, Queue } from 'bull';
import { ListLogsOption } from '../repos/models/list-logs.options';
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
describe('PipelinesService', () => {
let service: PipelinesService;
let repository: Repository<Pipeline>;
let pipeline: Pipeline;
let queue: Queue<ListLogsOption>;
beforeEach(async () => {
pipeline = Object.assign(new Pipeline(), {
@ -37,33 +33,17 @@ describe('PipelinesService', () => {
},
},
{
provide: getQueueToken(LIST_LOGS_TASK),
useValue: {
add: jest.fn().mockImplementation(() => ({ id: 1 } as Job)),
},
provide: AmqpConnection,
useValue: {},
},
],
}).compile();
service = module.get<PipelinesService>(PipelinesService);
repository = module.get(getRepositoryToken(Pipeline));
queue = module.get(getQueueToken(LIST_LOGS_TASK));
});
it('should be defined', () => {
expect(service).toBeDefined();
});
describe('listLogsForPipeline', () => {
it('should send task to queue.', async () => {
const add = jest.spyOn(queue, 'add');
await expect(
service.listLogsForPipeline('test-pipeline'),
).resolves.toEqual({ id: 1 });
expect(add).toBeCalledWith({
project: pipeline.project,
branch: pipeline.branch,
});
});
});
});