diff --git a/backend/tests/integration/api/recordings/bulk-delete-recording.test.ts b/backend/tests/integration/api/recordings/bulk-delete-recording.test.ts index c89972d..10ed7e5 100644 --- a/backend/tests/integration/api/recordings/bulk-delete-recording.test.ts +++ b/backend/tests/integration/api/recordings/bulk-delete-recording.test.ts @@ -4,21 +4,19 @@ import { deleteAllRecordings, deleteAllRooms, startTestServer, - stopRecording, - stopTestServer + stopRecording } from '../../../utils/helpers'; import { setupMultiRecordingsTestContext } from '../../../utils/test-scenarios'; import { expectValidationError } from '../../../utils/assertion-helpers'; describe('Recording API Tests', () => { beforeAll(async () => { - await startTestServer(); + startTestServer(); }); afterAll(async () => { await deleteAllRooms(); await deleteAllRecordings(); - await stopTestServer(); }); describe('Bulk Delete Recording Tests', () => { diff --git a/backend/tests/integration/api/recordings/start-recording.test.ts b/backend/tests/integration/api/recordings/start-recording.test.ts index 3145aaf..1b5bd48 100644 --- a/backend/tests/integration/api/recordings/start-recording.test.ts +++ b/backend/tests/integration/api/recordings/start-recording.test.ts @@ -7,13 +7,13 @@ import { startRecording, startTestServer, stopAllRecordings, - stopRecording, - stopTestServer + stopRecording } from '../../../utils/helpers.js'; import { setInternalConfig } from '../../../../src/config/internal-config.js'; import { errorRoomNotFound } from '../../../../src/models/error.model.js'; import { + expectValidationError, expectValidRecordingLocationHeader, expectValidStartRecordingResponse, expectValidStopRecordingResponse @@ -26,7 +26,7 @@ describe('Recording API Tests', () => { let room: MeetRoom, moderatorCookie: string; beforeAll(async () => { - await startTestServer(); + startTestServer(); }); afterAll(async () => { @@ -34,7 +34,6 @@ describe('Recording API Tests', () => { await disconnectFakeParticipants(); await deleteAllRooms(); await deleteAllRecordings(); - await stopTestServer(); }); describe('Start Recording Tests', () => { @@ -133,44 +132,19 @@ describe('Recording API Tests', () => { it('should reject request with roomId that becomes empty after sanitization', async () => { const response = await startRecording('!@#$%^&*()', moderatorCookie); - expect(response.status).toBe(422); - expect(response.body.details).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - field: 'roomId', - message: expect.stringContaining('cannot be empty after sanitization') - }) - ]) - ); + expectValidationError(response, 'roomId', 'cannot be empty after sanitization'); }); it('should reject request with non-string roomId', async () => { const response = await startRecording(123 as unknown as string, moderatorCookie); - - expect(response.status).toBe(422); - expect(response.body.details).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - field: 'roomId', - message: expect.stringContaining('Expected string') - }) - ]) - ); + expectValidationError(response, 'roomId', 'Expected string'); }); it('should reject request with very long roomId', async () => { const longRoomId = 'a'.repeat(101); const response = await startRecording(longRoomId, moderatorCookie); - expect(response.status).toBe(422); - expect(response.body.details).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - field: 'roomId', - message: expect.stringContaining('cannot exceed 100 characters') - }) - ]) - ); + expectValidationError(response, 'roomId', 'cannot exceed 100 characters'); }); it('should handle room that does not exist', async () => { diff --git a/backend/tests/integration/api/rooms/bulk-delete-rooms.test.ts b/backend/tests/integration/api/rooms/bulk-delete-rooms.test.ts index f611404..84d2fdb 100644 --- a/backend/tests/integration/api/rooms/bulk-delete-rooms.test.ts +++ b/backend/tests/integration/api/rooms/bulk-delete-rooms.test.ts @@ -3,7 +3,7 @@ import { createRoom, deleteAllRooms, startTestServer, - stopTestServer, + , getRoom, joinFakeParticipant, disconnectFakeParticipants, @@ -12,11 +12,11 @@ import { describe('Room API Tests', () => { beforeAll(async () => { - await startTestServer(); + startTestServer(); }); afterAll(async () => { - await stopTestServer(); + }); afterEach(async () => { diff --git a/backend/tests/integration/api/rooms/create-room.test.ts b/backend/tests/integration/api/rooms/create-room.test.ts index 7d0f78b..6e6b5df 100644 --- a/backend/tests/integration/api/rooms/create-room.test.ts +++ b/backend/tests/integration/api/rooms/create-room.test.ts @@ -6,7 +6,7 @@ import { deleteAllRooms, loginUserAsRole, startTestServer, - stopTestServer + } from '../../../utils/helpers.js'; import { UserRole } from '../../../../src/typings/ce/user.js'; import INTERNAL_CONFIG from '../../../../src/config/internal-config.js'; @@ -22,13 +22,13 @@ describe('Room API Tests', () => { let userCookie: string; beforeAll(async () => { - app = await startTestServer(); + app = startTestServer(); userCookie = await loginUserAsRole(UserRole.USER); }); afterAll(async () => { await deleteAllRooms(); - await stopTestServer(); + }); describe('Room Creation Tests', () => { diff --git a/backend/tests/integration/api/rooms/delete-room.test.ts b/backend/tests/integration/api/rooms/delete-room.test.ts index a2f6805..cab7d5d 100644 --- a/backend/tests/integration/api/rooms/delete-room.test.ts +++ b/backend/tests/integration/api/rooms/delete-room.test.ts @@ -3,22 +3,21 @@ import { createRoom, deleteAllRooms, startTestServer, - stopTestServer, + , getRoom, deleteRoom, joinFakeParticipant, - sleep, disconnectFakeParticipants } from '../../../utils/helpers.js'; import ms from 'ms'; describe('Room API Tests', () => { beforeAll(async () => { - await startTestServer(); + startTestServer(); }); afterAll(async () => { - await stopTestServer(); + }); afterEach(async () => { diff --git a/backend/tests/integration/api/rooms/garbage-collector.test.ts b/backend/tests/integration/api/rooms/garbage-collector.test.ts index 44f3ef4..10f32a2 100644 --- a/backend/tests/integration/api/rooms/garbage-collector.test.ts +++ b/backend/tests/integration/api/rooms/garbage-collector.test.ts @@ -3,7 +3,7 @@ import { createRoom, deleteAllRooms, startTestServer, - stopTestServer, + , getRoom, sleep, joinFakeParticipant, @@ -19,11 +19,11 @@ describe('Room Garbage Collector Tests', () => { setInternalConfig({ MIN_FUTURE_TIME_FOR_ROOM_AUTODELETION_DATE: '0s' }); - await startTestServer(); + startTestServer(); }); afterAll(async () => { - await stopTestServer(); + }); afterEach(async () => { diff --git a/backend/tests/integration/api/rooms/get-room.test.ts b/backend/tests/integration/api/rooms/get-room.test.ts index b453a2b..09d268d 100644 --- a/backend/tests/integration/api/rooms/get-room.test.ts +++ b/backend/tests/integration/api/rooms/get-room.test.ts @@ -1,19 +1,20 @@ import { describe, it, expect, beforeAll, afterAll, afterEach } from '@jest/globals'; -import { createRoom, deleteAllRooms, startTestServer, stopTestServer, getRoom } from '../../../utils/helpers.js'; +import { createRoom, deleteAllRooms, startTestServer, , getRoom } from '../../../utils/helpers.js'; import ms from 'ms'; import { expectSuccessRoomResponse, + expectValidationError, expectValidRoom, expectValidRoomWithFields } from '../../../utils/assertion-helpers.js'; describe('Room API Tests', () => { beforeAll(async () => { - await startTestServer(); + startTestServer(); }); afterAll(async () => { - await stopTestServer(); + }); afterEach(async () => { @@ -100,10 +101,7 @@ describe('Room API Tests', () => { it('should fail when roomId becomes empty after sanitization', async () => { const response = await getRoom('!!-*!@#$%^&*()_+{}|:"<>?'); - expect(response.status).toBe(422); - // Expect an error message indicating the resulting roomId is empty. - expect(response.body.error).toContain('Unprocessable Entity'); - expect(JSON.stringify(response.body.details)).toContain('roomId cannot be empty after sanitization'); + expectValidationError(response, 'roomId', 'cannot be empty after sanitization'); }); }); }); diff --git a/backend/tests/integration/api/rooms/get-rooms.test.ts b/backend/tests/integration/api/rooms/get-rooms.test.ts index b4912a5..971b6c8 100644 --- a/backend/tests/integration/api/rooms/get-rooms.test.ts +++ b/backend/tests/integration/api/rooms/get-rooms.test.ts @@ -1,5 +1,5 @@ import { describe, it, beforeAll, afterAll, afterEach } from '@jest/globals'; -import { createRoom, deleteAllRooms, getRooms, startTestServer, stopTestServer } from '../../../utils/helpers.js'; +import { createRoom, deleteAllRooms, getRooms, startTestServer, } from '../../../utils/helpers.js'; import ms from 'ms'; import { expectSuccessRoomsResponse, @@ -13,11 +13,11 @@ describe('Room API Tests', () => { const validAutoDeletionDate = Date.now() + ms('2h'); beforeAll(async () => { - await startTestServer(); + startTestServer(); }); afterAll(async () => { - await stopTestServer(); + }); afterEach(async () => { diff --git a/backend/tests/integration/api/rooms/update-room.test.ts b/backend/tests/integration/api/rooms/update-room.test.ts index 367657a..980a2d3 100644 --- a/backend/tests/integration/api/rooms/update-room.test.ts +++ b/backend/tests/integration/api/rooms/update-room.test.ts @@ -3,18 +3,18 @@ import { createRoom, deleteAllRooms, startTestServer, - stopTestServer, + , getRoom, updateRoomPreferences } from '../../../utils/helpers.js'; describe('Room API Tests', () => { beforeAll(async () => { - await startTestServer(); + startTestServer(); }); afterAll(async () => { - await stopTestServer(); + }); afterEach(async () => { diff --git a/backend/tests/integration/api/security/auth.test.ts b/backend/tests/integration/api/security/auth.test.ts index c7bf00a..c5b2c34 100644 --- a/backend/tests/integration/api/security/auth.test.ts +++ b/backend/tests/integration/api/security/auth.test.ts @@ -1,7 +1,7 @@ import request from 'supertest'; import { describe, it, expect, beforeAll, afterAll } from '@jest/globals'; import { Express } from 'express'; -import { loginUserAsRole, startTestServer, stopTestServer } from '../../../utils/helpers.js'; +import { loginUserAsRole, startTestServer, } from '../../../utils/helpers.js'; import INTERNAL_CONFIG from '../../../../src/config/internal-config.js'; import { UserRole } from '../../../../src/typings/ce/index.js'; @@ -11,11 +11,11 @@ describe('Authentication API Tests', () => { let app: Express; beforeAll(async () => { - app = await startTestServer(); + app = startTestServer(); }); afterAll(async () => { - await stopTestServer(); + }); describe('Login Tests', () => { diff --git a/backend/tests/integration/api/security/meeting-security.test.ts b/backend/tests/integration/api/security/meeting-security.test.ts index e8a4847..55f2781 100644 --- a/backend/tests/integration/api/security/meeting-security.test.ts +++ b/backend/tests/integration/api/security/meeting-security.test.ts @@ -1,7 +1,7 @@ import request from 'supertest'; import { describe, it, expect, beforeAll, afterAll } from '@jest/globals'; import { Express } from 'express'; -import { createRoom, generateParticipantToken, startTestServer, stopTestServer } from '../../../utils/helpers.js'; +import { createRoom, generateParticipantToken, startTestServer, } from '../../../utils/helpers.js'; import { UserRole } from '../../../../src/typings/ce/index.js'; import INTERNAL_CONFIG from '../../../../src/config/internal-config.js'; import { MeetRoomHelper } from '../../../../src/helpers/room.helper.js'; @@ -18,7 +18,7 @@ describe('Meeting API Security Tests', () => { let publisherCookie: string; beforeAll(async () => { - app = await startTestServer(); + app = startTestServer(); // Get cookie for admin adminCookie = await loginUserAsRole(UserRole.ADMIN); @@ -35,7 +35,7 @@ describe('Meeting API Security Tests', () => { afterAll(async () => { await deleteAllRooms(); - await stopTestServer(); + }, 20000); describe('End Meeting Tests', () => { diff --git a/backend/tests/integration/api/security/participant-security.test.ts b/backend/tests/integration/api/security/participant-security.test.ts index 0cc966c..637396a 100644 --- a/backend/tests/integration/api/security/participant-security.test.ts +++ b/backend/tests/integration/api/security/participant-security.test.ts @@ -1,7 +1,7 @@ import request from 'supertest'; import { describe, it, expect, beforeAll, afterAll } from '@jest/globals'; import { Express } from 'express'; -import { createRoom, startTestServer, stopTestServer } from '../../../utils/helpers.js'; +import { createRoom, startTestServer, } from '../../../utils/helpers.js'; import { AuthMode, UserRole } from '../../../../src/typings/ce/index.js'; import INTERNAL_CONFIG from '../../../../src/config/internal-config.js'; import { MeetRoomHelper } from '../../../../src/helpers/room.helper.js'; @@ -22,7 +22,7 @@ describe('Participant API Security Tests', () => { let publisherSecret: string; beforeAll(async () => { - app = await startTestServer(); + app = startTestServer(); // Get cookies for admin and user userCookie = await loginUserAsRole(UserRole.USER); @@ -38,7 +38,7 @@ describe('Participant API Security Tests', () => { afterAll(async () => { await deleteAllRooms(); - await stopTestServer(); + }, 20000); describe('Generate Participant Token Tests', () => { diff --git a/backend/tests/integration/api/security/recording-security.test.ts b/backend/tests/integration/api/security/recording-security.test.ts index 2715373..6e528a0 100644 --- a/backend/tests/integration/api/security/recording-security.test.ts +++ b/backend/tests/integration/api/security/recording-security.test.ts @@ -7,7 +7,7 @@ import { generateParticipantToken, loginUserAsRole, startTestServer, - stopTestServer + } from '../../../utils/helpers.js'; import { MEET_API_KEY } from '../../../../src/environment.js'; import INTERNAL_CONFIG from '../../../../src/config/internal-config.js'; @@ -30,7 +30,7 @@ describe('Recording API Security Tests', () => { let publisherCookie: string; beforeAll(async () => { - app = await startTestServer(); + app = startTestServer(); // Get cookies for admin and user userCookie = await loginUserAsRole(UserRole.USER); @@ -49,7 +49,7 @@ describe('Recording API Security Tests', () => { afterAll(async () => { await deleteAllRooms(); - await stopTestServer(); + }, 20000); describe('Start Recording Tests', () => { diff --git a/backend/tests/integration/api/security/room-security.test.ts b/backend/tests/integration/api/security/room-security.test.ts index 1472c00..8658477 100644 --- a/backend/tests/integration/api/security/room-security.test.ts +++ b/backend/tests/integration/api/security/room-security.test.ts @@ -1,7 +1,7 @@ import request from 'supertest'; import { describe, it, expect, beforeAll, beforeEach, afterAll } from '@jest/globals'; import { Express } from 'express'; -import { createRoom, generateParticipantToken, startTestServer, stopTestServer } from '../../../utils/helpers.js'; +import { createRoom, generateParticipantToken, startTestServer, } from '../../../utils/helpers.js'; import { AuthMode, UserRole } from '../../../../src/typings/ce/index.js'; import { MEET_API_KEY } from '../../../../src/environment.js'; import INTERNAL_CONFIG from '../../../../src/config/internal-config.js'; @@ -17,7 +17,7 @@ describe('Room API Security Tests', () => { let adminCookie: string; beforeAll(async () => { - app = await startTestServer(); + app = startTestServer(); // Get cookies for admin and user userCookie = await loginUserAsRole(UserRole.USER); @@ -26,7 +26,7 @@ describe('Room API Security Tests', () => { afterAll(async () => { await deleteAllRooms(); - await stopTestServer(); + }, 20000); describe('Create Room Tests', () => { diff --git a/backend/tests/utils/helpers.ts b/backend/tests/utils/helpers.ts index b634dad..6ca3f69 100644 --- a/backend/tests/utils/helpers.ts +++ b/backend/tests/utils/helpers.ts @@ -1,10 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import request, { Response } from 'supertest'; import { Express } from 'express'; -import { Server } from 'http'; import { createApp, registerDependencies } from '../../src/server.js'; import { - SERVER_PORT, MEET_API_KEY, MEET_USER, MEET_SECRET, @@ -35,8 +33,6 @@ const CREDENTIALS = { }; let app: Express; -let server: Server; - const fakeParticipantsProcesses = new Map(); export const sleep = (time: StringValue) => { @@ -46,56 +42,17 @@ export const sleep = (time: StringValue) => { /** * Starts the test server */ -export const startTestServer = async (): Promise => { - registerDependencies(); - app = createApp(); - - return await new Promise((resolve, reject) => { - server = app.listen(SERVER_PORT, async () => { - try { - // Check if the server is responding by hitting the health check route - const response = await request(app).get('/meet/health'); - - if (response.status === 200) { - console.log('Test server started and healthy!'); - resolve(app); - } else { - reject(new Error('Test server not healthy')); - } - } catch (error: any) { - reject(new Error('Failed to initialize server or global preferences: ' + error.message)); - } - }); - - // Handle server errors - server.on('error', (error: any) => reject(new Error(`Test server startup error: ${error.message}`))); - }); -}; - -/** - * Stops the test server - */ -export const stopTestServer = async (): Promise => { - if (!server) { - throw new Error('Server is not running'); +export const startTestServer = (): Express => { + if (app) { + return app; } - return new Promise((resolve, reject) => { - server.close((err) => { - if (err) { - reject(new Error(`Failed to stop server: ${err.message}`)); - } else { - console.log('Test server stopped.'); - resolve(); - } - - // Clear the app instance - app = undefined as unknown as Express; - server = undefined as unknown as Server; - }); - }); + registerDependencies(); + app = createApp(); + return app; }; + /** * Updates global security preferences */