test: improve test cleanup by adding disconnectFakeParticipants and consolidating room/recording deletions

This commit is contained in:
juancarmore 2025-06-23 13:57:44 +02:00
parent a7528ba8ac
commit b059acb159
20 changed files with 53 additions and 72 deletions

View File

@ -1,13 +1,13 @@
import { beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
import { afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { container } from '../../../../src/config/dependency-injector.config.js';
import { MeetStorageService } from '../../../../src/services/index.js';
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
import { expectValidationError } from '../../../helpers/assertion-helpers.js';
import {
getSecurityPreferences,
startTestServer,
updateSecurityPreferences
} from '../../../helpers/request-helpers.js';
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
import { container } from '../../../../src/config/dependency-injector.config.js';
import { MeetStorageService } from '../../../../src/services/index.js';
const defaultPreferences = {
authentication: {
@ -28,7 +28,7 @@ describe('Security Preferences API Tests', () => {
startTestServer();
});
beforeEach(async () => {
afterEach(async () => {
await restoreDefaultGlobalPreferences();
});

View File

@ -7,7 +7,6 @@ import {
deleteParticipant,
deleteRoom,
disconnectFakeParticipants,
sleep,
startTestServer
} from '../../../helpers/request-helpers.js';
import { RoomData, setupSingleRoom } from '../../../helpers/test-scenarios.js';
@ -66,7 +65,6 @@ describe('Meetings API Tests', () => {
let response = await deleteRoom(roomData.room.roomId, { force: true });
expect(response.status).toBe(204);
await sleep('1s'); // Wait a bit for the meeting to be closed and the room deleted
response = await deleteParticipant(roomData.room.roomId, participantName, roomData.moderatorCookie);
expect(response.status).toBe(404);
expect(response.body.error).toBe('Room Error');

View File

@ -1,5 +1,6 @@
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
import { container } from '../../../../src/config/index.js';
import { OpenViduMeetError } from '../../../../src/models/error.model.js';
import { LiveKitService } from '../../../../src/services/index.js';
import {
deleteAllRooms,
@ -7,11 +8,9 @@ import {
disconnectFakeParticipants,
endMeeting,
getRoom,
sleep,
startTestServer
} from '../../../helpers/request-helpers.js';
import { RoomData, setupSingleRoom } from '../../../helpers/test-scenarios.js';
import { OpenViduMeetError } from '../../../../src/models/error.model.js';
describe('Meetings API Tests', () => {
let livekitService: LiveKitService;
@ -75,7 +74,6 @@ describe('Meetings API Tests', () => {
let response = await deleteRoom(roomData.room.roomId, { force: true });
expect(response.status).toBe(204);
await sleep('1s'); // Wait a bit for the meeting to be closed and the room deleted
response = await endMeeting(roomData.room.roomId, roomData.moderatorCookie);
expect(response.status).toBe(404);
});

View File

@ -1,4 +1,4 @@
import { afterAll, afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { container } from '../../../../src/config';
import { MeetStorageService } from '../../../../src/services';
import { expectValidationError, expectValidStartRecordingResponse } from '../../../helpers/assertion-helpers';
@ -6,6 +6,7 @@ import {
bulkDeleteRecordings,
deleteAllRecordings,
deleteAllRooms,
disconnectFakeParticipants,
getAllRecordings,
startRecording,
startTestServer,
@ -16,14 +17,12 @@ import { setupMultiRecordingsTestContext } from '../../../helpers/test-scenarios
describe('Recording API Tests', () => {
beforeAll(async () => {
startTestServer();
});
afterAll(async () => {
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
await deleteAllRecordings();
});
afterEach(async () => {
// Ensure a clean state after each test
await disconnectFakeParticipants();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
const recordings = await getAllRecordings();
expect(recordings.body.recordings).toHaveLength(0);

View File

@ -7,6 +7,7 @@ import {
deleteAllRecordings,
deleteAllRooms,
deleteRecording,
disconnectFakeParticipants,
startRecording,
startTestServer,
stopAllRecordings,
@ -17,10 +18,11 @@ import { setupMultiRecordingsTestContext } from '../../../helpers/test-scenarios
describe('Recording API Tests', () => {
beforeAll(async () => {
startTestServer();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
await deleteAllRecordings();
});
afterAll(async () => {
await disconnectFakeParticipants();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
});

View File

@ -68,7 +68,7 @@ describe('Recording Garbage Collector Tests', () => {
jest.clearAllMocks();
// No configurar mocks globalmente para mejorar el aislamiento entre tests
// Do not set up global mocks here to improve test isolation
});
afterEach(async () => {
@ -76,7 +76,7 @@ describe('Recording Garbage Collector Tests', () => {
jest.clearAllMocks();
jest.restoreAllMocks();
// Restaurar explícitamente el comportamiento del mock para getLockCreatedAt
// Explicitly restore the mock behavior for getLockCreatedAt
if (mutexService.getLockCreatedAt && jest.isMockFunction(mutexService.getLockCreatedAt)) {
(mutexService.getLockCreatedAt as jest.Mock).mockReset();
}

View File

@ -4,29 +4,28 @@ import { expectSuccessRecordingMediaResponse, expectValidationError } from '../.
import {
deleteAllRecordings,
deleteAllRooms,
disconnectFakeParticipants,
getRecordingMedia,
startTestServer,
stopAllRecordings,
stopRecording
} from '../../../helpers/request-helpers';
import { setupMultiRecordingsTestContext } from '../../../helpers/test-scenarios';
describe('Recording API Tests', () => {
let room: MeetRoom, recordingId: string, moderatorCookie: string;
let room: MeetRoom, recordingId: string;
beforeAll(async () => {
startTestServer();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
await deleteAllRecordings();
const testContext = await setupMultiRecordingsTestContext(1, 1, 1, '3s');
const roomData = testContext.getRoomByIndex(0)!;
({ room, recordingId = '', moderatorCookie } = roomData);
({ room, recordingId = '' } = roomData);
});
afterAll(async () => {
await stopAllRecordings(moderatorCookie);
await disconnectFakeParticipants();
await Promise.all([deleteAllRecordings(), deleteAllRooms()]);
});

View File

@ -19,6 +19,7 @@ describe('Recording API Tests', () => {
beforeAll(async () => {
app = startTestServer();
await deleteAllRecordings();
const roomData = await setupSingleRoomWithRecording(true);
recordingId = roomData.recordingId!;
@ -26,8 +27,7 @@ describe('Recording API Tests', () => {
afterAll(async () => {
await disconnectFakeParticipants();
await deleteAllRooms();
await deleteAllRecordings();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
});
describe('Get Recording URL Tests', () => {

View File

@ -14,22 +14,20 @@ import { setupMultiRecordingsTestContext, TestContext } from '../../../helpers/t
describe('Recording API Tests', () => {
let context: TestContext | null = null;
let room: MeetRoom, moderatorCookie: string, recordingId: string;
let room: MeetRoom, recordingId: string;
beforeAll(async () => {
startTestServer();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
await deleteAllRecordings();
// Create a room and join a participant
context = await setupMultiRecordingsTestContext(1, 1, 1);
({ room, moderatorCookie, recordingId = '' } = context.getRoomByIndex(0)!);
({ room, recordingId = '' } = context.getRoomByIndex(0)!);
});
afterAll(async () => {
await stopAllRecordings(moderatorCookie);
await disconnectFakeParticipants();
await deleteAllRooms();
await deleteAllRecordings();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
context = null;
});

View File

@ -26,7 +26,7 @@ describe('Recordings API Tests', () => {
let context: TestContext | null = null;
let room: MeetRoom;
beforeAll(async () => {
beforeAll(() => {
startTestServer();
});
@ -40,7 +40,7 @@ describe('Recordings API Tests', () => {
afterAll(async () => {
await disconnectFakeParticipants();
await deleteAllRooms();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
context = null;
});

View File

@ -1,5 +1,7 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals';
import { afterEach, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { container } from '../../../../src/config/index.js';
import { setInternalConfig } from '../../../../src/config/internal-config.js';
import { SystemEventType } from '../../../../src/models/system-event.model.js';
import { RecordingService } from '../../../../src/services';
import {
expectValidStartRecordingResponse,
@ -11,6 +13,7 @@ import {
deleteAllRecordings,
deleteAllRooms,
deleteRecording,
disconnectFakeParticipants,
getRecording,
getRecordingMedia,
sleep,
@ -24,8 +27,6 @@ import {
setupMultiRoomTestContext,
TestContext
} from '../../../helpers/test-scenarios';
import { setInternalConfig } from '../../../../src/config/internal-config.js';
import { SystemEventType } from '../../../../src/models/system-event.model.js';
describe('Recording API Race Conditions Tests', () => {
let context: TestContext | null = null;
@ -33,13 +34,9 @@ describe('Recording API Race Conditions Tests', () => {
beforeAll(async () => {
startTestServer();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
recordingService = container.get(RecordingService);
});
beforeEach(async () => {
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
await deleteAllRecordings();
eventController.reset();
});
@ -51,6 +48,7 @@ describe('Recording API Race Conditions Tests', () => {
}
eventController.reset();
await disconnectFakeParticipants();
await Promise.all([deleteAllRecordings(), deleteAllRooms()]);
jest.clearAllMocks();
});

View File

@ -1,6 +1,8 @@
import { afterAll, afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { container } from '../../../../src/config/dependency-injector.config.js';
import { setInternalConfig } from '../../../../src/config/internal-config.js';
import { errorRoomNotFound } from '../../../../src/models/error.model.js';
import { MeetStorageService } from '../../../../src/services/index.js';
import { MeetRoom } from '../../../../src/typings/ce/index.js';
import {
expectValidationError,
@ -18,8 +20,6 @@ import {
stopRecording
} from '../../../helpers/request-helpers.js';
import { setupMultiRoomTestContext, TestContext } from '../../../helpers/test-scenarios.js';
import { container } from '../../../../src/config/dependency-injector.config.js';
import { MeetStorageService } from '../../../../src/services/index.js';
describe('Recording API Tests', () => {
let context: TestContext | null = null;
@ -27,11 +27,10 @@ describe('Recording API Tests', () => {
beforeAll(async () => {
startTestServer();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
await deleteAllRecordings();
});
afterAll(async () => {
await stopAllRecordings(moderatorCookie);
await disconnectFakeParticipants();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
});
@ -45,8 +44,7 @@ describe('Recording API Tests', () => {
afterAll(async () => {
await disconnectFakeParticipants();
await deleteAllRooms();
await deleteAllRecordings();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
context = null;
});
@ -77,7 +75,6 @@ describe('Recording API Tests', () => {
expect(archivedRoom?.publisherRoomUrl).toBeDefined();
expect(archivedRoom?.preferences).toBeDefined();
// Check if secrets file is created
const secretsResponse = await stopRecording(recordingId, moderatorCookie);
expectValidStopRecordingResponse(secretsResponse, recordingId, room.roomId);
});

View File

@ -18,15 +18,13 @@ describe('Recording API Tests', () => {
beforeAll(async () => {
startTestServer();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
await deleteAllRecordings();
});
afterAll(async () => {
await stopAllRecordings(moderatorCookie);
await disconnectFakeParticipants();
await deleteAllRooms();
await deleteAllRecordings();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
});
describe('Stop Recording Tests', () => {
@ -39,14 +37,6 @@ describe('Recording API Tests', () => {
recordingId = response.body.recordingId;
});
afterAll(async () => {
await disconnectFakeParticipants();
await stopAllRecordings(moderatorCookie);
await deleteAllRooms();
await deleteAllRecordings();
context = null;
});
it('should stop an active recording and return 202', async () => {
const response = await stopRecording(recordingId, moderatorCookie);
expectValidStopRecordingResponse(response, recordingId, room.roomId);

View File

@ -25,6 +25,7 @@ describe('Room Garbage Collector Tests', () => {
afterEach(async () => {
// Remove all rooms created
await disconnectFakeParticipants();
await deleteAllRooms();
});

View File

@ -23,8 +23,7 @@ describe('Room API Tests', () => {
afterAll(async () => {
await disconnectFakeParticipants();
await deleteAllRecordings();
await deleteAllRooms();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
});
describe('Generate Recording Token Tests', () => {

View File

@ -13,6 +13,7 @@ describe('Room API Tests', () => {
chatPreferences: { enabled: true },
virtualBackgroundPreferences: { enabled: true }
};
beforeAll(() => {
startTestServer();
});

View File

@ -201,6 +201,7 @@ describe('Authentication API Tests', () => {
const response = await getApiKeys();
expect(Array.isArray(response.body)).toBe(true);
if (response.body.length > 0) {
expect(response.body[0]).toHaveProperty('key');
expect(response.body[0]).toHaveProperty('creationDate');

View File

@ -33,8 +33,7 @@ describe('Recording API Security Tests', () => {
afterAll(async () => {
await disconnectFakeParticipants();
await deleteAllRooms();
await deleteAllRecordings();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
});
describe('Start Recording Tests', () => {

View File

@ -7,7 +7,9 @@ import { AuthMode, MeetRecordingAccess } from '../../../../src/typings/ce/index.
import {
changeSecurityPreferences,
createRoom,
deleteAllRecordings,
deleteAllRooms,
disconnectFakeParticipants,
loginUser,
startTestServer,
updateRecordingAccessPreferencesInRoom
@ -27,7 +29,8 @@ describe('Room API Security Tests', () => {
});
afterAll(async () => {
await deleteAllRooms();
await disconnectFakeParticipants();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
});
describe('Create Room Tests', () => {

View File

@ -10,7 +10,8 @@ import {
endMeeting,
updateWebbhookPreferences,
deleteAllRooms,
deleteRoom
deleteRoom,
disconnectFakeParticipants
} from '../../helpers/request-helpers.js';
import { MeetWebhookEvent, MeetWebhookEventType } from '../../../src/typings/ce/webhook.model.js';
@ -52,8 +53,8 @@ describe('Webhook Integration Tests', () => {
await stopWebhookServer();
const defaultPreferences = await storageService['getDefaultPreferences']();
await updateWebbhookPreferences(defaultPreferences.webhooksPreferences);
await deleteAllRecordings();
await deleteAllRooms();
await disconnectFakeParticipants();
await Promise.all([deleteAllRooms(), deleteAllRecordings()]);
});
it('should not send webhooks when disabled', async () => {
@ -116,9 +117,6 @@ describe('Webhook Integration Tests', () => {
// Forcefully delete the room
await deleteRoom(roomData.roomId, { force: true });
// Wait for the room to be closed
await sleep('1s');
// Verify 'meetingEnded' webhook is sent
expect(receivedWebhooks.length).toBeGreaterThanOrEqual(1);
const meetingEndedWebhook = receivedWebhooks.find((w) => w.body.event === MeetWebhookEventType.MEETING_ENDED);