From deadd90315e9ca875ae4d37815fbe7bc2312918a Mon Sep 17 00:00:00 2001 From: juancarmore Date: Thu, 15 May 2025 21:52:15 +0200 Subject: [PATCH] test: add integration tests for deleting participants in Meetings API --- backend/tests/helpers/request-helpers.ts | 10 +++ .../api/meetings/delete-participant.test.ts | 73 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 backend/tests/integration/api/meetings/delete-participant.test.ts diff --git a/backend/tests/helpers/request-helpers.ts b/backend/tests/helpers/request-helpers.ts index e56459b..40113ec 100644 --- a/backend/tests/helpers/request-helpers.ts +++ b/backend/tests/helpers/request-helpers.ts @@ -395,6 +395,16 @@ export const disconnectFakeParticipants = async () => { await sleep('1s'); }; +export const deleteParticipant = async (roomId: string, participantName: string, moderatorCookie: string) => { + checkAppIsRunning(); + + const response = await request(app) + .delete(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/meetings/${roomId}/participants/${participantName}`) + .set('Cookie', moderatorCookie) + .send(); + return response; +}; + export const endMeeting = async (roomId: string, moderatorCookie: string) => { checkAppIsRunning(); diff --git a/backend/tests/integration/api/meetings/delete-participant.test.ts b/backend/tests/integration/api/meetings/delete-participant.test.ts new file mode 100644 index 0000000..c0ef134 --- /dev/null +++ b/backend/tests/integration/api/meetings/delete-participant.test.ts @@ -0,0 +1,73 @@ +import { afterAll, beforeAll, beforeEach, 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, + deleteParticipant, + deleteRoom, + disconnectFakeParticipants, + startTestServer +} from '../../../helpers/request-helpers.js'; +import { RoomData, setupSingleRoom } from '../../../helpers/test-scenarios.js'; + +const participantName = 'TEST_PARTICIPANT'; + +describe('Meetings API Tests', () => { + let livekitService: LiveKitService; + let roomData: RoomData; + + beforeAll(async () => { + startTestServer(); + livekitService = container.get(LiveKitService); + }); + + afterAll(async () => { + await disconnectFakeParticipants(); + await deleteAllRooms(); + }); + + describe('Delete Participant Tests', () => { + beforeEach(async () => { + roomData = await setupSingleRoom(true); + }); + + it('should remove participant from LiveKit room', async () => { + // Check if participant exists before deletion + const participant = await livekitService.getParticipant(roomData.room.roomId, participantName); + expect(participant).toBeDefined(); + expect(participant.identity).toBe(participantName); + + // Delete the participant + const response = await deleteParticipant(roomData.room.roomId, participantName, roomData.moderatorCookie); + expect(response.status).toBe(200); + + // Check if the participant has been removed from LiveKit + try { + await livekitService.getParticipant(roomData.room.roomId, participantName); + } catch (error) { + expect((error as OpenViduMeetError).statusCode).toBe(404); + } + }); + + it('should fail with 404 if participant does not exist', async () => { + const response = await deleteParticipant( + roomData.room.roomId, + 'NON_EXISTENT_PARTICIPANT', + roomData.moderatorCookie + ); + expect(response.status).toBe(404); + expect(response.body.error).toBe('Participant Error'); + }); + + it('should fail with 404 if room does not exist', async () => { + // Delete the room to ensure it does not exist + let response = await deleteRoom(roomData.room.roomId, { force: true }); + expect(response.status).toBe(204); + + response = await deleteParticipant(roomData.room.roomId, participantName, roomData.moderatorCookie); + expect(response.status).toBe(404); + expect(response.body.error).toBe('Room Error'); + }); + }); +});