refactor(core): Use DI for eventBus code - Part 1 (no-changelog) (#8434)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-01-26 12:21:15 +01:00
committed by GitHub
parent 3cc0f81c02
commit 7c49004018
19 changed files with 399 additions and 355 deletions

View File

@@ -2,7 +2,7 @@ import Container from 'typedi';
import config from '@/config';
import { OrchestrationService } from '@/services/orchestration.service';
import type { RedisServiceWorkerResponseObject } from '@/services/redis/RedisServiceCommands';
import { eventBus } from '@/eventbus';
import { MessageEventBus } from '@/eventbus';
import { RedisService } from '@/services/redis.service';
import { handleWorkerResponseMessageMain } from '@/services/orchestration/main/handleWorkerResponseMessageMain';
import { handleCommandMessageMain } from '@/services/orchestration/main/handleCommandMessageMain';
@@ -37,9 +37,11 @@ const workerRestartEventbusResponse: RedisServiceWorkerResponseObject = {
describe('Orchestration Service', () => {
const logger = mockInstance(Logger);
mockInstance(Push);
mockInstance(RedisService);
mockInstance(ExternalSecretsManager);
const eventBus = mockInstance(MessageEventBus);
beforeAll(async () => {
mockInstance(RedisService);
mockInstance(ExternalSecretsManager);
jest.mock('ioredis', () => {
const Redis = require('ioredis-mock');
if (typeof Redis === 'object') {
@@ -110,8 +112,7 @@ describe('Orchestration Service', () => {
expect(logger.error).toHaveBeenCalled();
});
test('should reject command messages from iteslf', async () => {
jest.spyOn(eventBus, 'restart');
test('should reject command messages from itself', async () => {
const response = await handleCommandMessageMain(
JSON.stringify({ ...workerRestartEventbusResponse, senderId: queueModeId }),
);
@@ -119,7 +120,6 @@ describe('Orchestration Service', () => {
expect(response!.command).toEqual('restartEventBus');
expect(response!.senderId).toEqual(queueModeId);
expect(eventBus.restart).not.toHaveBeenCalled();
jest.spyOn(eventBus, 'restart').mockRestore();
});
test('should send command messages', async () => {