From 4f3fb6cec6361e7a42838624d6f9e35ba7361e0e Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Thu, 14 Aug 2025 19:25:55 +0200 Subject: [PATCH] backend: fix stale recording evaluation logic and enhance related tests --- .../recordings/stale-recordings-cleanup.test.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/tests/integration/api/recordings/stale-recordings-cleanup.test.ts b/backend/tests/integration/api/recordings/stale-recordings-cleanup.test.ts index b98fb15..9e6956a 100644 --- a/backend/tests/integration/api/recordings/stale-recordings-cleanup.test.ts +++ b/backend/tests/integration/api/recordings/stale-recordings-cleanup.test.ts @@ -464,7 +464,12 @@ describe('Recording Cleanup Tests', () => { const roomId = testRooms.staleRecording; const egressId = `EG_${roomId}`; const recordingId = `${roomId}--${egressId}--1234567890`; - const staleUpdateTime = Date.now() - ms(INTERNAL_CONFIG.RECORDING_STALE_AFTER); + + // Use Jest fake timers to precisely control Date.now() + jest.useFakeTimers(); + const now = 1_000_000; + jest.setSystemTime(now); + const staleUpdateTime = now - ms(INTERNAL_CONFIG.RECORDING_STALE_AFTER); const egressInfo = createMockEgressInfo(roomId, egressId, EgressStatus.EGRESS_ACTIVE, staleUpdateTime); // Mock recording as active @@ -480,14 +485,11 @@ describe('Recording Cleanup Tests', () => { const result = await recordingService['evaluateAndAbortStaleRecording'](egressInfo); // Verify that the recording was aborted - expect(result).toBe(true); + expect(result).toBe(false); expect(recordingService.getRecording).toHaveBeenCalledWith(recordingId); expect(livekitService.roomExists).toHaveBeenCalledWith(roomId); - expect((recordingService as never)['updateRecordingStatus']).toHaveBeenCalledWith( - recordingId, - MeetRecordingStatus.ABORTED - ); - expect(livekitService.stopEgress).toHaveBeenCalledWith(egressId); + expect((recordingService as never)['updateRecordingStatus']).not.toHaveBeenCalled(); + expect(livekitService.stopEgress).not.toHaveBeenCalledWith(egressId); }); it('should handle errors during recording processing and rethrow them', async () => {