tests: Refactor room creation tests to use ROOMS_PATH constant for API calls and update user login method
This commit is contained in:
parent
0e531948de
commit
df0a425eb7
@ -1,30 +1,32 @@
|
|||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
|
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
|
||||||
import { Express } from 'express';
|
import { Express } from 'express';
|
||||||
import { deleteAllRooms, login, startTestServer, stopTestServer } from '../../../utils/helpers.js';
|
import { deleteAllRooms, loginUserAsRole, startTestServer, stopTestServer } from '../../../utils/helpers.js';
|
||||||
const apiVersion = 'v1';
|
import { UserRole } from '../../../../src/typings/ce/user.js';
|
||||||
const baseUrl = `/meet/api/`;
|
import { MEET_API_BASE_PATH_V1 } from '../../../../src/environment.js';
|
||||||
const endpoint = '/rooms';
|
|
||||||
|
const ROOMS_PATH = `${MEET_API_BASE_PATH_V1}/rooms`;
|
||||||
|
|
||||||
describe('OpenVidu Meet Room API Tests', () => {
|
describe('OpenVidu Meet Room API Tests', () => {
|
||||||
|
const validAutoDeletionDate = Date.now() + 2 * 60 * 60 * 1000; // 2 hours ahead
|
||||||
|
|
||||||
let app: Express;
|
let app: Express;
|
||||||
let userCookie: string;
|
let userCookie: string;
|
||||||
const validAutoDeletionDate = Date.now() + 2 * 60 * 60 * 1000; // 2 hours ahead
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = await startTestServer();
|
app = await startTestServer();
|
||||||
userCookie = await login(app, 'user', 'user');
|
userCookie = await loginUserAsRole(UserRole.USER);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
// Remove all rooms created
|
await deleteAllRooms();
|
||||||
await deleteAllRooms(app);
|
|
||||||
await stopTestServer();
|
await stopTestServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Room Creation Tests', () => {
|
describe('Room Creation Tests', () => {
|
||||||
it('✅ Should create a room without autoDeletionDate (default behavior)', async () => {
|
it('✅ Should create a room without autoDeletionDate (default behavior)', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
.post(ROOMS_PATH)
|
||||||
.set('Cookie', userCookie)
|
.set('Cookie', userCookie)
|
||||||
.send({
|
.send({
|
||||||
roomIdPrefix: ' Test Room '
|
roomIdPrefix: ' Test Room '
|
||||||
@ -46,7 +48,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
|
|
||||||
it('✅ Should create a room with a valid autoDeletionDate', async () => {
|
it('✅ Should create a room with a valid autoDeletionDate', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
.post(ROOMS_PATH)
|
||||||
.set('Cookie', userCookie)
|
.set('Cookie', userCookie)
|
||||||
.send({
|
.send({
|
||||||
autoDeletionDate: validAutoDeletionDate,
|
autoDeletionDate: validAutoDeletionDate,
|
||||||
@ -74,11 +76,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(200);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body).toHaveProperty('creationDate');
|
expect(response.body).toHaveProperty('creationDate');
|
||||||
expect(response.body).toHaveProperty('autoDeletionDate');
|
expect(response.body).toHaveProperty('autoDeletionDate');
|
||||||
@ -103,11 +101,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
roomIdPrefix: 'TestRoom'
|
roomIdPrefix: 'TestRoom'
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
// Check that the error message contains the positive number validation
|
// Check that the error message contains the positive number validation
|
||||||
expect(response.body.error).toContain('Unprocessable Entity');
|
expect(response.body.error).toContain('Unprocessable Entity');
|
||||||
@ -120,11 +114,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
roomIdPrefix: 'TestRoom'
|
roomIdPrefix: 'TestRoom'
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(response.body.error).toContain('Unprocessable Entity');
|
expect(response.body.error).toContain('Unprocessable Entity');
|
||||||
expect(JSON.stringify(response.body.details)).toContain(
|
expect(JSON.stringify(response.body.details)).toContain(
|
||||||
@ -138,11 +128,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
roomIdPrefix: 'TestRoom'
|
roomIdPrefix: 'TestRoom'
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(JSON.stringify(response.body.details)).toContain('Expected number');
|
expect(JSON.stringify(response.body.details)).toContain('Expected number');
|
||||||
});
|
});
|
||||||
@ -153,11 +139,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
roomIdPrefix: 'TestRoom'
|
roomIdPrefix: 'TestRoom'
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(JSON.stringify(response.body.details)).toContain('Expected number');
|
expect(JSON.stringify(response.body.details)).toContain('Expected number');
|
||||||
});
|
});
|
||||||
@ -168,11 +150,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
roomIdPrefix: 'TestRoom'
|
roomIdPrefix: 'TestRoom'
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(JSON.stringify(response.body.details)).toContain('Expected number');
|
expect(JSON.stringify(response.body.details)).toContain('Expected number');
|
||||||
});
|
});
|
||||||
@ -183,11 +161,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
autoDeletionDate: validAutoDeletionDate
|
autoDeletionDate: validAutoDeletionDate
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(JSON.stringify(response.body.details)).toContain('Expected string');
|
expect(JSON.stringify(response.body.details)).toContain('Expected string');
|
||||||
});
|
});
|
||||||
@ -198,11 +172,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
autoDeletionDate: validAutoDeletionDate
|
autoDeletionDate: validAutoDeletionDate
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(JSON.stringify(response.body.details)).toContain('Expected string');
|
expect(JSON.stringify(response.body.details)).toContain('Expected string');
|
||||||
});
|
});
|
||||||
@ -214,11 +184,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
preferences: 'invalid-preferences'
|
preferences: 'invalid-preferences'
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(JSON.stringify(response.body.details)).toContain('Expected object');
|
expect(JSON.stringify(response.body.details)).toContain('Expected object');
|
||||||
});
|
});
|
||||||
@ -236,11 +202,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app).post(ROOMS_PATH).set('Cookie', userCookie).send(payload).expect(422);
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
|
||||||
.set('Cookie', userCookie)
|
|
||||||
.send(payload)
|
|
||||||
.expect(422);
|
|
||||||
|
|
||||||
expect(JSON.stringify(response.body.details)).toContain('Expected boolean');
|
expect(JSON.stringify(response.body.details)).toContain('Expected boolean');
|
||||||
});
|
});
|
||||||
@ -248,7 +210,7 @@ describe('OpenVidu Meet Room API Tests', () => {
|
|||||||
it('should fail with invalid JSON payload', async () => {
|
it('should fail with invalid JSON payload', async () => {
|
||||||
// In this case, instead of sending JSON object, send an invalid JSON string.
|
// In this case, instead of sending JSON object, send an invalid JSON string.
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post(`${baseUrl}${apiVersion}${endpoint}`)
|
.post(ROOMS_PATH)
|
||||||
.set('Cookie', userCookie)
|
.set('Cookie', userCookie)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send('{"roomIdPrefix": "TestRoom",') // invalid JSON syntax
|
.send('{"roomIdPrefix": "TestRoom",') // invalid JSON syntax
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user