tests: Fix broken tests by changing expected error responses and reorganize imports

This commit is contained in:
juancarmore 2025-04-30 16:19:23 +02:00
parent 94d526df07
commit 5a66b2f623
10 changed files with 60 additions and 67 deletions

View File

@ -1,6 +1,7 @@
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
import { container } from '../../../../src/config';
import { MeetStorageService } from '../../../../src/services';
import { MeetRoom } from '../../../../src/typings/ce';
import { expectValidationError, expectValidStartRecordingResponse } from '../../../helpers/assertion-helpers';
import {
deleteAllRecordings,
@ -12,7 +13,6 @@ import {
stopRecording
} from '../../../helpers/request-helpers';
import { setupMultiRecordingsTestContext } from '../../../helpers/test-scenarios';
import { MeetRoom } from '../../../../src/typings/ce';
describe('Recording API Tests', () => {
beforeAll(() => {

View File

@ -1,18 +1,17 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals';
import { EgressInfo, EgressStatus, Room } from 'livekit-server-sdk';
import ms from 'ms';
import { Lock } from 'redlock';
import { container } from '../../../../src/config/index.js';
import INTERNAL_CONFIG from '../../../../src/config/internal-config.js';
import { MeetLock } from '../../../../src/helpers/index.js';
import {
RecordingService,
MutexService,
LiveKitService,
LoggerService,
MutexService,
RecordingService,
RedisLock
} from '../../../../src/services/index.js';
import { container } from '../../../../src/config/dependency-injector.config.js';
import { EgressInfo, EgressStatus, Room } from 'livekit-server-sdk';
import INTERNAL_CONFIG from '../../../../src/config/internal-config.js';
import { Lock } from 'redlock';
import { startTestServer } from '../../../helpers/request-helpers.js';
describe('Recording Garbage Collector Tests', () => {

View File

@ -1,4 +1,5 @@
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
import { MeetRoom } from '../../../../src/typings/ce';
import { expectSuccessRecordingMediaResponse, expectValidationError } from '../../../helpers/assertion-helpers';
import {
deleteAllRecordings,
@ -9,7 +10,6 @@ import {
stopRecording
} from '../../../helpers/request-helpers';
import { setupMultiRecordingsTestContext } from '../../../helpers/test-scenarios';
import { MeetRoom } from '../../../../src/typings/ce';
describe('Recording API Tests', () => {
let room: MeetRoom, recordingId: string, moderatorCookie: string;
@ -27,6 +27,7 @@ describe('Recording API Tests', () => {
await stopAllRecordings(moderatorCookie);
await Promise.all([deleteAllRecordings(), deleteAllRooms()]);
});
describe('Recording Media Tests', () => {
it('should return 200 when requesting the full media content', async () => {
const response = await getRecordingMedia(recordingId);
@ -157,7 +158,7 @@ describe('Recording API Tests', () => {
// Request a range beyond the file size
const response = await getRecordingMedia(recordingId, `bytes=${fullSize + 1}-${fullSize + 1000}`);
expect(response.status).toBe(416);
expect(response.body).toHaveProperty('name', 'Recording Error');
expect(response.body).toHaveProperty('error', 'Recording Error');
expect(response.body).toHaveProperty('message');
expect(response.body.message).toContain(`Recording '${recordingId}' range not satisfiable`);
expect(response.body.message).toMatch(/File size: \d+/);
@ -170,7 +171,7 @@ describe('Recording API Tests', () => {
// Attempt to get the media of an active recording
const response = await getRecordingMedia(activeRecordingId);
expect(response.status).toBe(409);
expect(response.body).toHaveProperty('name', 'Recording Error');
expect(response.body).toHaveProperty('error', 'Recording Error');
expect(response.body).toHaveProperty('message');
expect(response.body.message).toContain(`Recording '${activeRecordingId}' is not stopped yet`);

View File

@ -1,4 +1,7 @@
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
import { errorRecordingNotFound } from '../../../../src/models/error.model.js';
import { MeetRecordingStatus, MeetRoom } from '../../../../src/typings/ce/index.js';
import { expectValidationError, expectValidGetRecordingResponse } from '../../../helpers/assertion-helpers.js';
import {
deleteAllRecordings,
deleteAllRooms,
@ -7,11 +10,6 @@ import {
startTestServer,
stopAllRecordings
} from '../../../helpers/request-helpers.js';
import { errorRecordingNotFound } from '../../../../src/models/error.model.js';
import { MeetRecordingStatus } from '../../../../src/typings/ce/recording.model.js';
import { MeetRoom } from '../../../../src/typings/ce/room.js';
import { expectValidationError, expectValidGetRecordingResponse } from '../../../helpers/assertion-helpers.js';
import { setupMultiRecordingsTestContext, TestContext } from '../../../helpers/test-scenarios.js';
describe('Recording API Tests', () => {

View File

@ -1,4 +1,11 @@
import { describe, it, expect, beforeAll, afterEach, afterAll } from '@jest/globals';
import { afterAll, afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { MeetRecordingInfo, MeetRecordingStatus, MeetRoom } from '../../../../src/typings/ce/index.js';
import {
expectSuccessListRecordingResponse,
expectValidationError,
expectValidRecording,
expectValidRecordingWithFields
} from '../../../helpers/assertion-helpers.js';
import {
deleteAllRecordings,
deleteAllRooms,
@ -6,16 +13,7 @@ import {
getAllRecordings,
startTestServer
} from '../../../helpers/request-helpers.js';
import {
expectValidationError,
expectSuccessListRecordingResponse,
expectValidRecordingWithFields,
expectValidRecording
} from '../../../helpers/assertion-helpers.js';
import { RoomData, setupMultiRecordingsTestContext, TestContext } from '../../../helpers/test-scenarios.js';
import { MeetRoom } from '../../../../src/typings/ce/room.js';
import { MeetRecordingInfo, MeetRecordingStatus } from '../../../../src/typings/ce/recording.model.js';
describe('Recordings API Tests', () => {
let context: TestContext | null = null;

View File

@ -1,35 +1,34 @@
import { describe, it, expect, beforeAll, afterAll, afterEach, jest } from '@jest/globals';
import { afterEach, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { container } from '../../../../src/config/index.js';
import { RecordingService, TaskSchedulerService } from '../../../../src/services';
import {
expectValidStartRecordingResponse,
expectValidStopRecordingResponse
} from '../../../helpers/assertion-helpers';
import { eventController } from '../../../helpers/event-controller';
import {
startRecording,
sleep,
bulkDeleteRecordings,
deleteAllRecordings,
deleteAllRooms,
startTestServer,
stopRecording,
stopAllRecordings,
getRecordingMedia,
deleteRecording,
bulkDeleteRecordings
getRecordingMedia,
sleep,
startRecording,
startTestServer,
stopAllRecordings,
stopRecording
} from '../../../helpers/request-helpers';
import {
setupMultiRecordingsTestContext,
setupMultiRoomTestContext,
TestContext
} from '../../../helpers/test-scenarios';
import {
expectValidStartRecordingResponse,
expectValidStopRecordingResponse
} from '../../../helpers/assertion-helpers';
import { RecordingService, TaskSchedulerService } from '../../../../src/services';
import { container } from '../../../../src/config/dependency-injector.config';
describe('Recording API Race Conditions Tests', () => {
let context: TestContext | null = null;
let recordingService: RecordingService;
let taskSchedulerService: TaskSchedulerService;
beforeAll(async () => {
startTestServer();
recordingService = container.get(RecordingService);
@ -48,8 +47,6 @@ describe('Recording API Race Conditions Tests', () => {
jest.clearAllMocks();
});
afterAll(async () => {});
it('should start recordings concurrently in two rooms and stop one before RECORDING_ACTIVE is received for the other', async () => {
context = await setupMultiRoomTestContext(2, true);
const roomDataA = context.getRoomByIndex(0);

View File

@ -1,5 +1,13 @@
import { afterAll, afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { setInternalConfig } from '../../../../src/config/internal-config.js';
import { errorRoomNotFound } from '../../../../src/models/error.model.js';
import { MeetRoom } from '../../../../src/typings/ce/index.js';
import {
expectValidationError,
expectValidRecordingLocationHeader,
expectValidStartRecordingResponse,
expectValidStopRecordingResponse
} from '../../../helpers/assertion-helpers.js';
import {
deleteAllRecordings,
deleteAllRooms,
@ -10,15 +18,6 @@ import {
stopAllRecordings,
stopRecording
} from '../../../helpers/request-helpers.js';
import { errorRoomNotFound } from '../../../../src/models/error.model.js';
import { MeetRoom } from '../../../../src/typings/ce/room.js';
import {
expectValidationError,
expectValidRecordingLocationHeader,
expectValidStartRecordingResponse,
expectValidStopRecordingResponse
} from '../../../helpers/assertion-helpers.js';
import { setupMultiRoomTestContext, TestContext } from '../../../helpers/test-scenarios.js';
describe('Recording API Tests', () => {
@ -117,7 +116,7 @@ describe('Recording API Tests', () => {
const response = await startRecording(room.roomId, moderatorCookie);
// Room exists but it has no participants
expect(response.status).toBe(409);
expect(response.body.message).toContain(`The room '${room.roomId}' has no participants`);
expect(response.body.message).toContain(`Room '${room.roomId}' has no participants`);
});
it('should sanitize roomId and reject the request with 409 due to no participants', async () => {
@ -126,7 +125,7 @@ describe('Recording API Tests', () => {
console.log('Response:', response.body);
expect(response.status).toBe(409);
expect(response.body.message).toContain(`The room '${room.roomId}' has no participants`);
expect(response.body.message).toContain(`Room '${room.roomId}' has no participants`);
});
it('should reject request with roomId that becomes empty after sanitization', async () => {
@ -152,7 +151,7 @@ describe('Recording API Tests', () => {
const error = errorRoomNotFound('non-existing-room-id');
expect(response.status).toBe(404);
expect(response.body).toEqual({
name: error.name,
error: error.name,
message: error.message
});
});

View File

@ -1,15 +1,15 @@
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
import { expectValidStopRecordingResponse, expectErrorResponse } from '../../../helpers/assertion-helpers';
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
import { MeetRoom } from '../../../../src/typings/ce';
import { expectErrorResponse, expectValidStopRecordingResponse } from '../../../helpers/assertion-helpers';
import {
startRecording,
disconnectFakeParticipants,
stopAllRecordings,
stopRecording,
deleteAllRecordings,
deleteAllRooms,
startTestServer
disconnectFakeParticipants,
startRecording,
startTestServer,
stopAllRecordings,
stopRecording
} from '../../../helpers/request-helpers';
import { MeetRoom } from '../../../../src/typings/ce';
import { setupMultiRoomTestContext, TestContext } from '../../../helpers/test-scenarios';
describe('Recording API Tests', () => {
@ -19,6 +19,7 @@ describe('Recording API Tests', () => {
beforeAll(async () => {
startTestServer();
});
afterAll(async () => {
await stopAllRecordings(moderatorCookie);
await disconnectFakeParticipants();
@ -67,7 +68,7 @@ describe('Recording API Tests', () => {
it('should return 404 when recordingId does not exist', async () => {
const response = await stopRecording(`${room.roomId}--EG_123--444`, moderatorCookie);
expect(response.status).toBe(404);
expect(response.body.name).toBe('Recording Error');
expect(response.body.error).toBe('Recording Error');
expect(response.body.message).toContain('not found');
});

View File

@ -130,7 +130,7 @@ describe('Room API Tests', () => {
expect(response.status).toBe(202);
expect(response.body.message).toContain(`Rooms ${room1.roomId}, ${room2.roomId} marked for deletion`);
expect(response.body.message).toContain(`Rooms '${room1.roomId}, ${room2.roomId}' marked for deletion`);
expect(response.body.deleted).toBeUndefined();
// Verify that the rooms are marked for deletion

View File

@ -187,7 +187,7 @@ describe('Room API Tests', () => {
.expect(400);
expect(response.body.error).toContain('Bad Request');
expect(response.body.message).toContain('Malformed Body');
expect(response.body.message).toContain('Malformed body');
});
it('should fail when roomIdPrefix is too long', async () => {