backend: Clean up unnecessary test files
This commit is contained in:
parent
c090e255c2
commit
2a1448330c
@ -1,165 +0,0 @@
|
|||||||
import request from 'supertest';
|
|
||||||
import { describe, it, expect, beforeAll, afterAll, jest } from '@jest/globals';
|
|
||||||
import { Express } from 'express';
|
|
||||||
import { startTestServer, stopTestServer } from '../../../utils/server-setup.js';
|
|
||||||
import { container } from '../../../../src/config/dependency-injector.config.js';
|
|
||||||
import { LiveKitService } from '../../../../src/services/livekit.service.js';
|
|
||||||
import { LoggerService } from '../../../../src/services/logger.service.js';
|
|
||||||
|
|
||||||
const apiVersion = 'v1';
|
|
||||||
const baseUrl = `/embedded/api/`;
|
|
||||||
const endpoint = '/participant';
|
|
||||||
describe('Embedded Auth API Tests', () => {
|
|
||||||
let app: Express;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
console.log('Server not started. Running in test mode.');
|
|
||||||
app = await startTestServer();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await stopTestServer();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('✅ Should generate a embedded url with valid input', async () => {
|
|
||||||
console.log;
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
participantName: 'OpenVidu',
|
|
||||||
roomName: 'TestRoom'
|
|
||||||
})
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('embeddedURL');
|
|
||||||
expect(typeof response.body.embeddedURL).toBe('string');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('✅ Should generate an embedded url with valid input and some permissions', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
participantName: 'OpenVidu',
|
|
||||||
roomName: 'TestRoom',
|
|
||||||
permissions: {
|
|
||||||
canRecord: true,
|
|
||||||
canChat: false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('embeddedURL');
|
|
||||||
expect(typeof response.body.embeddedURL).toBe('string');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 400 when missing participantName', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
roomName: 'TestRoom'
|
|
||||||
})
|
|
||||||
.expect(400);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('errors');
|
|
||||||
expect(response.body.errors[0].message).toContain("must have required property 'participantName'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 400 when missing roomName', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
participantName: 'OpenVidu'
|
|
||||||
})
|
|
||||||
.expect(400);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('errors');
|
|
||||||
expect(response.body.errors[0].message).toContain("must have required property 'roomName'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 400 when participantName has wrong type', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
participantName: 22,
|
|
||||||
roomName: 'TestRoom'
|
|
||||||
})
|
|
||||||
.expect(400);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('errors');
|
|
||||||
expect(response.body.errors[0].message).toContain('must be string');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 400 when missing body request', async () => {
|
|
||||||
const response = await request(app).post(`${baseUrl}${apiVersion}${endpoint}`).send().expect(415);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('error');
|
|
||||||
expect(response.body.error).toContain('Unsupported Media Type');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 500 when an error occurs in generateToken', async () => {
|
|
||||||
jest.mock('../../../src/services/livekit.service');
|
|
||||||
jest.mock('../../../src/services/logger.service');
|
|
||||||
|
|
||||||
const mockLiveKitService = container.get(LiveKitService);
|
|
||||||
mockLiveKitService.generateToken = jest
|
|
||||||
.fn()
|
|
||||||
.mockRejectedValue(new Error('LiveKit Error') as never) as jest.MockedFunction<
|
|
||||||
(options: any) => Promise<string>
|
|
||||||
>;
|
|
||||||
// Mock the logger service
|
|
||||||
const mockLoggerService = container.get(LoggerService);
|
|
||||||
mockLoggerService.error = jest.fn();
|
|
||||||
|
|
||||||
const response = await request(app).post(`${baseUrl}${apiVersion}${endpoint}`).send({
|
|
||||||
participantName: 'testParticipant',
|
|
||||||
roomName: 'testRoom'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert: Check that the status is 500 and error message is correct
|
|
||||||
expect(response.status).toBe(500);
|
|
||||||
expect(response.body.error).toBe('Internal server error');
|
|
||||||
expect(mockLoggerService.error).toHaveBeenCalledWith('Internal server error: Error: LiveKit Error');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 400 when permissions have wrong types', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
participantName: 'OpenVidu',
|
|
||||||
roomName: 'TestRoom',
|
|
||||||
permissions: {
|
|
||||||
canRecord: 'yes', // Incorrect type
|
|
||||||
canChat: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.expect(400);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('errors');
|
|
||||||
expect(response.body.errors[0].message).toContain('must be boolean');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 404 when requesting a non-existent API version (v2)', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}v2${endpoint}`)
|
|
||||||
.send({
|
|
||||||
participantName: 'OpenVidu',
|
|
||||||
roomName: 'TestRoom'
|
|
||||||
})
|
|
||||||
.expect(404);
|
|
||||||
|
|
||||||
console.log(response.body);
|
|
||||||
expect(response.body).toHaveProperty('error');
|
|
||||||
expect(response.body.error).toBe('Not found');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 415 when unsupported content type is provided', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Content-Type', 'application/xml') // Unsupported content type
|
|
||||||
.send('<xml><participantName>OpenVidu</participantName><roomName>TestRoom</roomName></xml>')
|
|
||||||
.expect(415);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('error');
|
|
||||||
expect(response.body.error).toContain('Unsupported Media Type');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,172 +0,0 @@
|
|||||||
import request from 'supertest';
|
|
||||||
import { describe, it, expect, beforeAll, afterAll, jest } from '@jest/globals';
|
|
||||||
import { Express } from 'express';
|
|
||||||
import { startTestServer, stopTestServer } from '../../../utils/server-setup.js';
|
|
||||||
import { Room } from 'livekit-server-sdk';
|
|
||||||
import { container } from '../../../../src/config/dependency-injector.config.js';
|
|
||||||
import { LiveKitService } from '../../../../src/services/livekit.service.js';
|
|
||||||
import { LoggerService } from '../../../../src/services/logger.service.js';
|
|
||||||
|
|
||||||
const apiVersion = 'v1';
|
|
||||||
const baseUrl = `/meet/api/`;
|
|
||||||
const endpoint = '/rooms';
|
|
||||||
|
|
||||||
describe('Room Request Validation Tests', () => {
|
|
||||||
let app: Express;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
app = await startTestServer();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await stopTestServer();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('✅ Should create a room with only required fields', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 1772129829000
|
|
||||||
})
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('creationDate');
|
|
||||||
expect(response.body).toHaveProperty('autoDeletionDate');
|
|
||||||
expect(response.body).toHaveProperty('maxParticipants');
|
|
||||||
expect(response.body).toHaveProperty('preferences');
|
|
||||||
expect(response.body).toHaveProperty('moderatorRoomUrl');
|
|
||||||
expect(response.body).toHaveProperty('publisherRoomUrl');
|
|
||||||
expect(response.body).toHaveProperty('viewerRoomUrl');
|
|
||||||
expect(response.body).not.toHaveProperty('permissions');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('✅ Should create a room with full attributes', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 1772129829000,
|
|
||||||
roomNamePrefix: 'Conference',
|
|
||||||
maxParticipants: 10,
|
|
||||||
preferences: {
|
|
||||||
recordingPreferences: { enabled: true },
|
|
||||||
chatPreferences: { enabled: false },
|
|
||||||
virtualBackgroundPreferences: { enabled: true }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('creationDate');
|
|
||||||
expect(response.body).toHaveProperty('autoDeletionDate');
|
|
||||||
expect(response.body).toHaveProperty('maxParticipants');
|
|
||||||
expect(response.body).toHaveProperty('preferences');
|
|
||||||
expect(response.body).toHaveProperty('moderatorRoomUrl');
|
|
||||||
expect(response.body).toHaveProperty('publisherRoomUrl');
|
|
||||||
expect(response.body).toHaveProperty('viewerRoomUrl');
|
|
||||||
expect(response.body).not.toHaveProperty('permissions');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('✅ Should use default values for missing optional fields', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 1772129829000
|
|
||||||
})
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('preferences');
|
|
||||||
expect(response.body.preferences).toEqual({
|
|
||||||
recordingPreferences: { enabled: true },
|
|
||||||
chatPreferences: { enabled: true },
|
|
||||||
virtualBackgroundPreferences: { enabled: true }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 422 when missing autoDeletionDate', async () => {
|
|
||||||
const response = await request(app).post(`${baseUrl}${apiVersion}${endpoint}`).send({}).expect(422);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('error', 'Unprocessable Entity');
|
|
||||||
expect(response.body.details[0].field).toBe('autoDeletionDate');
|
|
||||||
expect(response.body.details[0].message).toContain('Required');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 422 when autoDeletionDate is in the past', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 1600000000000
|
|
||||||
})
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(response.body.details[0].message).toContain('Expiration date must be in the future');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 422 when maxParticipants is negative', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 1772129829000,
|
|
||||||
maxParticipants: -5
|
|
||||||
})
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(response.body.details[0].field).toBe('maxParticipants');
|
|
||||||
expect(response.body.details[0].message).toContain('Max participants must be a positive integer');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 422 when maxParticipants is not a number', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 1772129829000,
|
|
||||||
maxParticipants: 'ten'
|
|
||||||
})
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(response.body.details[0].message).toContain('Expected number, received string');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 422 when autoDeletionDate is not a number', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 'tomorrow'
|
|
||||||
})
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(response.body.details[0].message).toContain('Expected number, received string');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 422 when preferences contain wrong types', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 1772129829000,
|
|
||||||
preferences: {
|
|
||||||
recordingPreferences: { enabled: 'yes' },
|
|
||||||
chatPreferences: { enabled: 'no' }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(response.body.details[0].message).toContain('Expected boolean, received string');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('❌ Should return 500 when an internal server error occurs', async () => {
|
|
||||||
jest.mock('../../../../src/services/livekit.service');
|
|
||||||
jest.mock('../../../../src/services/logger.service');
|
|
||||||
|
|
||||||
const mockLiveKitService = container.get(LiveKitService);
|
|
||||||
mockLiveKitService.createRoom = jest.fn<() => Promise<Room>>().mockRejectedValue(new Error('LiveKit Error'));
|
|
||||||
|
|
||||||
const mockLoggerService = container.get(LoggerService);
|
|
||||||
mockLoggerService.error = jest.fn();
|
|
||||||
|
|
||||||
const response = await request(app).post(`${baseUrl}${apiVersion}${endpoint}`).send({
|
|
||||||
autoDeletionDate: 1772129829000,
|
|
||||||
roomNamePrefix: 'OpenVidu'
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response.status).toBe(500);
|
|
||||||
expect(response.body.message).toContain('Internal server error');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,84 +0,0 @@
|
|||||||
import request from 'supertest';
|
|
||||||
import { describe, it, expect, beforeAll, afterAll, jest, afterEach } from '@jest/globals';
|
|
||||||
import { Express } from 'express';
|
|
||||||
import { startTestServer, stopTestServer } from '../../../utils/server-setup.js';
|
|
||||||
import { container } from '../../../../src/config/dependency-injector.config.js';
|
|
||||||
import { LiveKitService } from '../../../../src/services/livekit.service.js';
|
|
||||||
import { LoggerService } from '../../../../src/services/logger.service.js';
|
|
||||||
import { Room } from 'livekit-server-sdk';
|
|
||||||
|
|
||||||
const apiVersion = 'v1';
|
|
||||||
const baseUrl = `/meet/api/`;
|
|
||||||
const endpoint = '/rooms';
|
|
||||||
describe('OpenVidu Meet Room API Tests', () => {
|
|
||||||
let app: Express;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
console.log('Server not started. Running in test mode.');
|
|
||||||
app = await startTestServer();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
const rooms = await request(app).get(`${baseUrl}${apiVersion}${endpoint}`);
|
|
||||||
|
|
||||||
for (const room of rooms.body) {
|
|
||||||
console.log(`Deleting room ${room.roomName}`);
|
|
||||||
await request(app).delete(`${baseUrl}${apiVersion}${endpoint}/${room.roomName}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await stopTestServer();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should create a room', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.send({
|
|
||||||
autoDeletionDate: 1772129829000,
|
|
||||||
roomNamePrefix: 'OpenVidu',
|
|
||||||
maxParticipants: 10,
|
|
||||||
preferences: {
|
|
||||||
chatPreferences: { enabled: true },
|
|
||||||
recordingPreferences: { enabled: true },
|
|
||||||
virtualBackgroundPreferences: { enabled: true }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('creationDate');
|
|
||||||
expect(response.body).toHaveProperty('autoDeletionDate');
|
|
||||||
expect(response.body).toHaveProperty('maxParticipants');
|
|
||||||
expect(response.body).toHaveProperty('preferences');
|
|
||||||
expect(response.body).toHaveProperty('moderatorRoomUrl');
|
|
||||||
expect(response.body).toHaveProperty('publisherRoomUrl');
|
|
||||||
expect(response.body).toHaveProperty('viewerRoomUrl');
|
|
||||||
expect(response.body).not.toHaveProperty('permissions');
|
|
||||||
|
|
||||||
const room = await request(app).get(`${baseUrl}${apiVersion}${endpoint}/${response.body.roomName}`).expect(200);
|
|
||||||
|
|
||||||
expect(room.body).toHaveProperty('creationDate');
|
|
||||||
expect(room.body.roomName).toBe(response.body.roomName);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('❌ Should return 500 when an internal server error occurs', async () => {
|
|
||||||
jest.mock('../../../../src/services/livekit.service');
|
|
||||||
jest.mock('../../../../src/services/logger.service');
|
|
||||||
|
|
||||||
const mockLiveKitService = container.get(LiveKitService);
|
|
||||||
mockLiveKitService.createRoom = jest.fn<() => Promise<Room>>().mockRejectedValue(new Error('LiveKit Error'));
|
|
||||||
|
|
||||||
const mockLoggerService = container.get(LoggerService);
|
|
||||||
mockLoggerService.error = jest.fn();
|
|
||||||
|
|
||||||
const response = await request(app).post(`${baseUrl}${apiVersion}${endpoint}`).send({
|
|
||||||
autoDeletionDate: 1772129829000,
|
|
||||||
roomNamePrefix: 'OpenVidu'
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response.status).toBe(500);
|
|
||||||
expect(response.body.message).toContain('Internal server error');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
import { Room } from 'livekit-server-sdk';
|
|
||||||
import { LiveKitService } from '../../src/services/livekit.service.js';
|
|
||||||
import { jest } from '@jest/globals';
|
|
||||||
|
|
||||||
// Mock para LiveKitService
|
|
||||||
export const mockLiveKitService = {
|
|
||||||
createRoom:
|
|
||||||
// Añade más mocks si es necesario
|
|
||||||
};
|
|
||||||
|
|
||||||
// Puedes hacer un mock de otras funciones también si es necesario
|
|
||||||
Loading…
x
Reference in New Issue
Block a user