refactor(core): Introduce RedisClientService (no-changelog) (#9774)
This commit is contained in:
@@ -14,6 +14,13 @@ import { Push } from '@/push';
|
||||
import { ActiveWorkflowManager } from '@/ActiveWorkflowManager';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
import type { WorkflowActivateMode } from 'n8n-workflow';
|
||||
import { RedisClientService } from '@/services/redis/redis-client.service';
|
||||
import type Redis from 'ioredis';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
|
||||
const redisClientService = mockInstance(RedisClientService);
|
||||
const mockRedisClient = mock<Redis>();
|
||||
redisClientService.createClient.mockReturnValue(mockRedisClient);
|
||||
|
||||
const os = Container.get(OrchestrationService);
|
||||
const handler = Container.get(OrchestrationHandlerMainService);
|
||||
@@ -43,20 +50,6 @@ describe('Orchestration Service', () => {
|
||||
const eventBus = mockInstance(MessageEventBus);
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.mock('ioredis', () => {
|
||||
const Redis = require('ioredis-mock');
|
||||
if (typeof Redis === 'object') {
|
||||
// the first mock is an ioredis shim because ioredis-mock depends on it
|
||||
// https://github.com/stipsan/ioredis-mock/blob/master/src/index.js#L101-L111
|
||||
return {
|
||||
Command: { _transformer: { argument: {}, reply: {} } },
|
||||
};
|
||||
}
|
||||
// second mock for our code
|
||||
return function (...args: any) {
|
||||
return new Redis(args);
|
||||
};
|
||||
});
|
||||
jest.mock('@/services/redis/RedisServicePubSubPublisher', () => {
|
||||
return jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
|
||||
@@ -4,6 +4,21 @@ import config from '@/config';
|
||||
import { RedisService } from '@/services/redis.service';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
|
||||
jest.mock('ioredis', () => {
|
||||
const Redis = require('ioredis-mock');
|
||||
if (typeof Redis === 'object') {
|
||||
// the first mock is an ioredis shim because ioredis-mock depends on it
|
||||
// https://github.com/stipsan/ioredis-mock/blob/master/src/index.js#L101-L111
|
||||
return {
|
||||
Command: { _transformer: { argument: {}, reply: {} } },
|
||||
};
|
||||
}
|
||||
// second mock for our code
|
||||
return function (...args: any) {
|
||||
return new Redis(args);
|
||||
};
|
||||
});
|
||||
|
||||
mockInstance(Logger);
|
||||
const redisService = Container.get(RedisService);
|
||||
|
||||
@@ -15,20 +30,6 @@ const PUBSUB_CHANNEL = 'testchannel';
|
||||
|
||||
describe('RedisService', () => {
|
||||
beforeAll(async () => {
|
||||
jest.mock('ioredis', () => {
|
||||
const Redis = require('ioredis-mock');
|
||||
if (typeof Redis === 'object') {
|
||||
// the first mock is an ioredis shim because ioredis-mock depends on it
|
||||
// https://github.com/stipsan/ioredis-mock/blob/master/src/index.js#L101-L111
|
||||
return {
|
||||
Command: { _transformer: { argument: {}, reply: {} } },
|
||||
};
|
||||
}
|
||||
// second mock for our code
|
||||
return function (...args: any) {
|
||||
return new Redis(args);
|
||||
};
|
||||
});
|
||||
setDefaultConfig();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user