tests: Add setupSingleRoom function in test-scenarios.ts and refactor code
This commit is contained in:
parent
78f6d7d8cc
commit
e90fac28b5
@ -1,22 +1,22 @@
|
|||||||
|
import { StringValue } from 'ms';
|
||||||
import { MeetRoomHelper } from '../../src/helpers';
|
import { MeetRoomHelper } from '../../src/helpers';
|
||||||
|
import { MeetRoom } from '../../src/typings/ce';
|
||||||
|
import { expectValidStartRecordingResponse } from './assertion-helpers';
|
||||||
import {
|
import {
|
||||||
createRoom,
|
createRoom,
|
||||||
generateParticipantToken,
|
generateParticipantToken,
|
||||||
joinFakeParticipant,
|
joinFakeParticipant,
|
||||||
loginUserAsRole,
|
|
||||||
sleep,
|
sleep,
|
||||||
startRecording,
|
startRecording,
|
||||||
stopRecording
|
stopRecording
|
||||||
} from './request-helpers';
|
} from './request-helpers';
|
||||||
|
|
||||||
import ms, { StringValue } from 'ms';
|
|
||||||
import { MeetRoom, UserRole } from '../../src/typings/ce';
|
|
||||||
import { expectValidStartRecordingResponse } from './assertion-helpers';
|
|
||||||
|
|
||||||
export interface RoomData {
|
export interface RoomData {
|
||||||
room: MeetRoom;
|
room: MeetRoom;
|
||||||
moderatorCookie: string;
|
|
||||||
moderatorSecret: string;
|
moderatorSecret: string;
|
||||||
|
moderatorCookie: string;
|
||||||
|
publisherSecret: string;
|
||||||
|
publisherCookie: string;
|
||||||
recordingId?: string;
|
recordingId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,29 +27,47 @@ export interface TestContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configura un escenario de prueba con dos salas para pruebas de grabación concurrente
|
* Creates a single room with optional participant.
|
||||||
|
*
|
||||||
|
* @param withParticipant Whether to join a fake participant in the room.
|
||||||
|
* @returns Room data including secrets and cookies.
|
||||||
*/
|
*/
|
||||||
export async function setupMultiRoomTestContext(numRooms: number, withParticipants: boolean): Promise<TestContext> {
|
export const setupSingleRoom = async (withParticipant = false): Promise<RoomData> => {
|
||||||
const adminCookie = await loginUserAsRole(UserRole.ADMIN);
|
const room = await createRoom({
|
||||||
|
roomIdPrefix: 'TEST_ROOM'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Extract the room secrets and generate participant tokens, saved as cookies
|
||||||
|
const { moderatorSecret, publisherSecret } = MeetRoomHelper.extractSecretsFromRoom(room);
|
||||||
|
const [moderatorCookie, publisherCookie] = await Promise.all([
|
||||||
|
generateParticipantToken(room.roomId, 'MODERATOR', moderatorSecret),
|
||||||
|
generateParticipantToken(room.roomId, 'PUBLISHER', publisherSecret),
|
||||||
|
// Join participant if needed
|
||||||
|
withParticipant ? joinFakeParticipant(room.roomId, 'TEST_PARTICIPANT') : Promise.resolve()
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
room,
|
||||||
|
moderatorSecret,
|
||||||
|
moderatorCookie,
|
||||||
|
publisherSecret,
|
||||||
|
publisherCookie
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a test context with multiple rooms and optional participants.
|
||||||
|
*
|
||||||
|
* @param numRooms Number of rooms to create.
|
||||||
|
* @param withParticipants Whether to join fake participants in the rooms.
|
||||||
|
* @returns Test context with created rooms and their data.
|
||||||
|
*/
|
||||||
|
export const setupMultiRoomTestContext = async (numRooms: number, withParticipants: boolean): Promise<TestContext> => {
|
||||||
const rooms: RoomData[] = [];
|
const rooms: RoomData[] = [];
|
||||||
|
|
||||||
// Create additional rooms
|
|
||||||
for (let i = 0; i < numRooms; i++) {
|
for (let i = 0; i < numRooms; i++) {
|
||||||
const room = await createRoom({
|
const roomData = await setupSingleRoom(withParticipants);
|
||||||
roomIdPrefix: `test-recording-room-${i + 1}`
|
rooms.push(roomData);
|
||||||
});
|
|
||||||
const { moderatorSecret } = MeetRoomHelper.extractSecretsFromRoom(room);
|
|
||||||
const [moderatorCookie, _] = await Promise.all([
|
|
||||||
generateParticipantToken(adminCookie, room.roomId, `Moderator-${i + 1}`, moderatorSecret),
|
|
||||||
// Join participant (if needed) concurrently with token generation
|
|
||||||
withParticipants ? joinFakeParticipant(room.roomId, `TEST_P-${i + 1}`) : Promise.resolve()
|
|
||||||
]);
|
|
||||||
|
|
||||||
rooms.push({
|
|
||||||
room,
|
|
||||||
moderatorCookie,
|
|
||||||
moderatorSecret
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -70,24 +88,24 @@ export async function setupMultiRoomTestContext(numRooms: number, withParticipan
|
|||||||
return rooms[rooms.length - 1];
|
return rooms[rooms.length - 1];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quickly creates multiple recordings for bulk delete testing.
|
* Quickly creates multiple recordings
|
||||||
* Allows customizing how many recordings to start and how many to stop after a delay.
|
* Allows customizing how many recordings to start and how many to stop after a delay.
|
||||||
*
|
*
|
||||||
* @param numRooms Number of rooms to use.
|
* @param numRooms Number of rooms to use.
|
||||||
* @param numStarts Number of recordings to start.
|
* @param numStarts Number of recordings to start.
|
||||||
* @param numStops Number of recordings to stop after the delay.
|
* @param numStops Number of recordings to stop after the delay.
|
||||||
* @param stopDelayMs Delay in milliseconds before stopping recordings.
|
* @param stopDelay Delay before stopping recordings.
|
||||||
* @returns Test context with created recordings (some stopped, some still running).
|
* @returns Test context with created recordings (some stopped, some still running).
|
||||||
*/
|
*/
|
||||||
export async function setupMultiRecordingsTestContext(
|
export const setupMultiRecordingsTestContext = async (
|
||||||
numRooms: number,
|
numRooms: number,
|
||||||
numStarts: number,
|
numStarts: number,
|
||||||
numStops: number,
|
numStops: number,
|
||||||
stopDelay: StringValue
|
stopDelay?: StringValue
|
||||||
): Promise<TestContext> {
|
): Promise<TestContext> => {
|
||||||
// Setup rooms with participants
|
// Setup rooms with participants
|
||||||
const testContext = await setupMultiRoomTestContext(numRooms, true);
|
const testContext = await setupMultiRoomTestContext(numRooms, true);
|
||||||
|
|
||||||
@ -111,7 +129,7 @@ export async function setupMultiRecordingsTestContext(
|
|||||||
const startedRooms = await Promise.all(startPromises);
|
const startedRooms = await Promise.all(startPromises);
|
||||||
|
|
||||||
// Wait for the configured delay before stopping recordings
|
// Wait for the configured delay before stopping recordings
|
||||||
if (ms(stopDelay) > 0) {
|
if (stopDelay) {
|
||||||
await sleep(stopDelay);
|
await sleep(stopDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,4 +147,4 @@ export async function setupMultiRecordingsTestContext(
|
|||||||
console.log(`Stopped ${stoppedIds.length} recordings after ${stopDelay}ms:`, stoppedIds);
|
console.log(`Stopped ${stoppedIds.length} recordings after ${stopDelay}ms:`, stoppedIds);
|
||||||
|
|
||||||
return testContext;
|
return testContext;
|
||||||
}
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user