feat(pipelines): 添加查询 commit logs 接口。
This commit is contained in:
@ -2,25 +2,68 @@ 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';
|
||||
|
||||
describe('PipelinesService', () => {
|
||||
let service: PipelinesService;
|
||||
let repository: Repository<Pipeline>;
|
||||
let pipeline: Pipeline;
|
||||
let queue: Queue<ListLogsOption>;
|
||||
|
||||
beforeEach(async () => {
|
||||
pipeline = Object.assign(new Pipeline(), {
|
||||
id: 'test-pipeline',
|
||||
name: 'pipeline',
|
||||
branch: 'master',
|
||||
projectId: 'test-project',
|
||||
project: Object.assign(new Project(), {
|
||||
id: 'test-project',
|
||||
name: 'project',
|
||||
} as Project),
|
||||
} as Pipeline);
|
||||
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
PipelinesService,
|
||||
{
|
||||
provide: getRepositoryToken(Pipeline),
|
||||
useValue: {},
|
||||
useValue: {
|
||||
findOneOrFail: jest.fn().mockImplementation(() => pipeline),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: getQueueToken(LIST_LOGS_TASK),
|
||||
useValue: {
|
||||
add: jest.fn().mockImplementation(() => ({ id: 1 } as Job)),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).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(1);
|
||||
expect(add).toBeCalledWith({
|
||||
project: pipeline.project,
|
||||
branch: pipeline.branch,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user