test: add integration tests for retrieving room roles and permissions

This commit is contained in:
juancarmore 2025-05-13 12:09:57 +02:00
parent 65a5a1fe85
commit e45420ac0f
3 changed files with 164 additions and 5 deletions

View File

@ -5,7 +5,8 @@ import {
MeetRecordingInfo,
MeetRecordingStatus,
MeetRoom,
MeetRoomPreferences
MeetRoomPreferences,
ParticipantRole
} from '../../src/typings/ce';
const RECORDINGS_PATH = `${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings`;
@ -427,3 +428,87 @@ export const expectSuccessListRecordingResponse = (
expect(response.body.pagination.maxItems).toBeLessThanOrEqual(100);
expect(response.body.pagination.maxItems).toBe(maxItems);
};
export const expectValidRoomRolesAndPermissionsResponse = (response: any, roomId: string) => {
expect(response.status).toBe(200);
expect(response.body).toEqual(
expect.arrayContaining([
{
role: ParticipantRole.MODERATOR,
permissions: getPermissions(roomId, ParticipantRole.MODERATOR)
},
{
role: ParticipantRole.PUBLISHER,
permissions: getPermissions(roomId, ParticipantRole.PUBLISHER)
}
])
);
};
export const expectValidRoomRoleAndPermissionsResponse = (
response: any,
roomId: string,
participantRole: ParticipantRole
) => {
expect(response.status).toBe(200);
expect(response.body).toEqual({
role: participantRole,
permissions: getPermissions(roomId, participantRole)
});
};
const getPermissions = (roomId: string, role: ParticipantRole) => {
switch (role) {
case ParticipantRole.MODERATOR:
return {
livekit: {
roomCreate: true,
roomJoin: true,
roomList: true,
roomRecord: true,
roomAdmin: true,
room: roomId,
ingressAdmin: true,
canPublish: true,
canSubscribe: true,
canPublishData: true,
canUpdateOwnMetadata: true,
hidden: false,
recorder: true,
agent: false
},
openvidu: {
canPublishScreen: true,
canRecord: true,
canChat: true,
canChangeVirtualBackground: true
}
};
case ParticipantRole.PUBLISHER:
return {
livekit: {
roomJoin: true,
roomList: true,
roomRecord: false,
roomAdmin: false,
room: roomId,
ingressAdmin: false,
canPublish: true,
canSubscribe: true,
canPublishData: true,
canUpdateOwnMetadata: true,
hidden: false,
recorder: false,
agent: false
},
openvidu: {
canPublishScreen: true,
canRecord: false,
canChat: true,
canChangeVirtualBackground: true
}
};
default:
throw new Error(`Unknown role ${role}`);
}
};

View File

@ -289,6 +289,24 @@ export const runReleaseActiveRecordingLock = async (roomId: string) => {
await recordingService.releaseRecordingLockIfNoEgress(roomId);
};
export const getRoomRoles = async (roomId: string) => {
checkAppIsRunning();
const response = await request(app)
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/rooms/${roomId}/roles`)
.send();
return response;
};
export const getRoomRoleBySecret = async (roomId: string, secret: string) => {
checkAppIsRunning();
const response = await request(app)
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/rooms/${roomId}/roles/${secret}`)
.send();
return response;
};
/**
* Generates a participant token for a room and returns the cookie containing the token
*/
@ -368,9 +386,6 @@ export const endMeeting = async (roomId: string, moderatorCookie: string) => {
return response;
};
/**
* Generates a token for retrieving/deleting recordings from a room and returns the cookie containing the token
*/
export const generateRecordingToken = async (roomId: string, secret: string) => {
checkAppIsRunning();
@ -379,7 +394,6 @@ export const generateRecordingToken = async (roomId: string, secret: string) =>
authMode: AuthMode.NONE
});
// Generate the recording token
const response = await request(app)
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/rooms/${roomId}/recording-token`)
.send({

View File

@ -0,0 +1,60 @@
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
import { ParticipantRole } from '../../../../src/typings/ce/index.js';
import {
expectValidRoomRoleAndPermissionsResponse,
expectValidRoomRolesAndPermissionsResponse
} from '../../../helpers/assertion-helpers.js';
import {
deleteAllRooms,
getRoomRoleBySecret,
getRoomRoles,
startTestServer
} from '../../../helpers/request-helpers.js';
import { RoomData, setupSingleRoom } from '../../../helpers/test-scenarios.js';
describe('Room API Tests', () => {
let roomData: RoomData;
beforeAll(async () => {
startTestServer();
roomData = await setupSingleRoom();
});
afterAll(async () => {
await deleteAllRooms();
});
describe('Get Room Roles Tests', () => {
it('should retrieve all roles and associated permissions for a room', async () => {
const response = await getRoomRoles(roomData.room.roomId);
expectValidRoomRolesAndPermissionsResponse(response, roomData.room.roomId);
});
it('should return a 404 error if the room does not exist', async () => {
const response = await getRoomRoles('non-existent-room-id');
expect(response.status).toBe(404);
});
});
describe('Get Room Role Tests', () => {
it('should retrieve moderator role and associated permissions for a room with a valid moderator secret', async () => {
const response = await getRoomRoleBySecret(roomData.room.roomId, roomData.moderatorSecret);
expectValidRoomRoleAndPermissionsResponse(response, roomData.room.roomId, ParticipantRole.MODERATOR);
});
it('should retrieve publisher role and associated permissions for a room with a valid publisher secret', async () => {
const response = await getRoomRoleBySecret(roomData.room.roomId, roomData.publisherSecret);
expectValidRoomRoleAndPermissionsResponse(response, roomData.room.roomId, ParticipantRole.PUBLISHER);
});
it('should return a 404 error if the room does not exist', async () => {
const response = await getRoomRoleBySecret('non-existent-room-id', roomData.moderatorSecret);
expect(response.status).toBe(404);
});
it('should return a 400 error if the secret is invalid', async () => {
const response = await getRoomRoleBySecret(roomData.room.roomId, 'invalid-secret');
expect(response.status).toBe(400);
});
});
});