test: update event controller to use DistributedEventService and correct

This commit is contained in:
juancarmore 2025-07-09 01:32:29 +02:00
parent 64d54f7973
commit 82d81e7598
2 changed files with 13 additions and 7 deletions

View File

@ -1,9 +1,9 @@
import { container } from '../../src/config/index.js'; import { container } from '../../src/config/index.js';
import { SystemEventType } from '../../src/models/system-event.model.js'; import { DistributedEventType } from '../../src/models';
import { SystemEventService } from '../../src/services/index.js'; import { DistributedEventService } from '../../src/services';
export const eventController = { export const eventController = {
systemEventService: undefined as unknown as SystemEventService, systemEventService: undefined as unknown as DistributedEventService,
pausedEvents: new Map<string, Array<{ eventType: string; payload: any }>>(), pausedEvents: new Map<string, Array<{ eventType: string; payload: any }>>(),
isInitialized: false, isInitialized: false,
originalEmit: null as any, originalEmit: null as any,
@ -11,7 +11,7 @@ export const eventController = {
initialize() { initialize() {
if (this.isInitialized) return; if (this.isInitialized) return;
this.systemEventService = container.get(SystemEventService); this.systemEventService = container.get(DistributedEventService);
this.originalEmit = this.systemEventService['emitter'].emit; this.originalEmit = this.systemEventService['emitter'].emit;
this.pausedEvents.clear(); this.pausedEvents.clear();
this.isInitialized = true; this.isInitialized = true;
@ -22,7 +22,7 @@ export const eventController = {
// Check if the event is paused for the room // Check if the event is paused for the room
if ( if (
eventType === SystemEventType.RECORDING_ACTIVE && eventType === DistributedEventType.RECORDING_ACTIVE &&
payload?.roomId && payload?.roomId &&
this.pausedEvents.has(payload.roomId) this.pausedEvents.has(payload.roomId)
) { ) {

View File

@ -68,7 +68,10 @@ describe('Recording API Race Conditions Tests', () => {
try { try {
// Attempt to start recording // Attempt to start recording
const result = await startRecording(roomData.room.roomId, roomData.moderatorCookie); const result = await startRecording(roomData.room.roomId, roomData.moderatorCookie);
expect(eventServiceOffSpy).toHaveBeenCalledWith(DistributedEventType.RECORDING_ACTIVE, expect.any(Function)); expect(eventServiceOffSpy).toHaveBeenCalledWith(
DistributedEventType.RECORDING_ACTIVE,
expect.any(Function)
);
expect(handleRecordingLockTimeoutSpy).not.toHaveBeenCalledWith( expect(handleRecordingLockTimeoutSpy).not.toHaveBeenCalledWith(
'', // empty recordingId since it never started '', // empty recordingId since it never started
roomData.room.roomId roomData.room.roomId
@ -121,7 +124,10 @@ describe('Recording API Race Conditions Tests', () => {
// Start recording with a short timeout // Start recording with a short timeout
const result = await startRecording(roomData.room.roomId, roomData.moderatorCookie); const result = await startRecording(roomData.room.roomId, roomData.moderatorCookie);
expect(eventServiceOffSpy).toHaveBeenCalledWith(DistributedEventType.RECORDING_ACTIVE, expect.any(Function)); expect(eventServiceOffSpy).toHaveBeenCalledWith(
DistributedEventType.RECORDING_ACTIVE,
expect.any(Function)
);
// Expect the recording to fail due to timeout // Expect the recording to fail due to timeout
expect(handleTimeoutSpy).toHaveBeenCalledWith( expect(handleTimeoutSpy).toHaveBeenCalledWith(
'', // empty recordingId since it never started '', // empty recordingId since it never started