test: pass cases

This commit is contained in:
Ivan Li 2021-04-05 20:20:43 +08:00
parent 0e0781c4c4
commit 24a2f80e46
4 changed files with 16 additions and 6 deletions

View File

@ -1,8 +1,8 @@
import { DEFAULT_PUB_SUB_NAME } from '../pub-sub.constants';
export function getPubSubToken(name) {
export function getPubSubToken(name = DEFAULT_PUB_SUB_NAME) {
return `app:pub-usb:${name || DEFAULT_PUB_SUB_NAME}`;
}
export function getPubSubConfigToken(name) {
export function getPubSubConfigToken(name = DEFAULT_PUB_SUB_NAME) {
return `app:pub-usb:config:${name || DEFAULT_PUB_SUB_NAME}`;
}

View File

@ -1,6 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PipelineTaskLogsService } from './pipeline-task-logs.service';
import { RedisService } from 'nestjs-redis';
import { getPubSubToken } from '../commons/pub-sub/utils/token';
describe('PipelineTaskLogsService', () => {
let service: PipelineTaskLogsService;
@ -13,6 +14,10 @@ describe('PipelineTaskLogsService', () => {
provide: RedisService,
useValue: {},
},
{
provide: getPubSubToken(),
useValue: {},
},
],
}).compile();

View File

@ -174,7 +174,7 @@ describe('PipelineTaskConsumer', () => {
await consumer.doTask(job);
expect(updateTask).toHaveBeenCalledTimes(2);
expect(updateTask).toHaveBeenCalledTimes(4);
expect(updateTask.mock.calls[0][0].startedAt).toBeDefined();
expect(updateTask.mock.calls[1][0].endedAt).toBeDefined();
expect(updateTask.mock.calls[1][0].status).toEqual(TaskStatuses.success);
@ -192,7 +192,7 @@ describe('PipelineTaskConsumer', () => {
await consumer.doTask(job);
expect(updateTask).toHaveBeenCalledTimes(2);
expect(updateTask).toHaveBeenCalledTimes(4);
expect(updateTask.mock.calls[0][0].startedAt).toBeDefined();
expect(updateTask.mock.calls[1][0].endedAt).toBeDefined();
expect(updateTask.mock.calls[1][0].status).toEqual(TaskStatuses.failed);
@ -211,7 +211,7 @@ describe('PipelineTaskConsumer', () => {
await consumer.doTask(job);
expect(runScript).toHaveBeenCalledTimes(1);
expect(updateTask).toHaveBeenCalledTimes(2);
expect(updateTask).toHaveBeenCalledTimes(4);
const taskDto: PipelineTask = updateTask.mock.calls[0][0];
expect(taskDto.logs).toHaveLength(2);
expect(taskDto.logs[0].status).toEqual(TaskStatuses.success);
@ -232,7 +232,7 @@ describe('PipelineTaskConsumer', () => {
await consumer.doTask(job);
expect(updateTask).toHaveBeenCalledTimes(2);
expect(updateTask).toHaveBeenCalledTimes(4);
const taskDto: PipelineTask = updateTask.mock.calls[0][0];
expect(taskDto.logs).toHaveLength(2);
expect(taskDto.logs[0].status).toEqual(TaskStatuses.success);

View File

@ -10,6 +10,7 @@ import { EntityNotFoundError } from 'typeorm/error/EntityNotFoundError';
import { Repository } from 'typeorm';
import { Queue } from 'bull';
import { LockFailedException } from '../commons/exceptions/lock-failed.exception';
import { getPubSubToken } from '../commons/pub-sub/utils/token';
describe('PipelineTasksService', () => {
let service: PipelineTasksService;
@ -68,6 +69,10 @@ describe('PipelineTasksService', () => {
getClient: jest.fn(() => redisClient),
},
},
{
provide: getPubSubToken(),
useValue: {},
},
],
}).compile();