backend: Refactor bulk delete recording tests to utilize expectValidationError for improved clarity and consistency
This commit is contained in:
parent
ba88183f26
commit
80237c2d76
@ -8,6 +8,7 @@ import {
|
|||||||
stopTestServer
|
stopTestServer
|
||||||
} from '../../../utils/helpers';
|
} from '../../../utils/helpers';
|
||||||
import { setupMultiRecordingsTestContext } from '../../../utils/test-scenarios';
|
import { setupMultiRecordingsTestContext } from '../../../utils/test-scenarios';
|
||||||
|
import { expectValidationError } from '../../../utils/assertion-helpers';
|
||||||
|
|
||||||
describe('Recording API Tests', () => {
|
describe('Recording API Tests', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
@ -121,67 +122,30 @@ describe('Recording API Tests', () => {
|
|||||||
|
|
||||||
describe('Bulk Delete Recording Validation', () => {
|
describe('Bulk Delete Recording Validation', () => {
|
||||||
it('should handle empty recordingIds array gracefully', async () => {
|
it('should handle empty recordingIds array gracefully', async () => {
|
||||||
const deleteResponse = await bulkDeleteRecordings([]);
|
const response = await bulkDeleteRecordings([]);
|
||||||
|
|
||||||
expect(deleteResponse.status).toBe(422);
|
expectValidationError(response, 'recordingIds', 'recordingIds must contain at least one item');
|
||||||
expect(deleteResponse.body).toEqual({
|
|
||||||
details: [
|
|
||||||
{
|
|
||||||
field: 'recordingIds',
|
|
||||||
message: 'recordingIds must contain at least one item'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
error: 'Unprocessable Entity',
|
|
||||||
message: 'Invalid request'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject a CSV string with invalid format', async () => {
|
it('should reject a CSV string with invalid format', async () => {
|
||||||
const invalidRecordingIds = 'invalid--recording.id,invalid--EG_111--5678';
|
const invalidRecordingIds = 'invalid--recording.id,invalid--EG_111--5678';
|
||||||
const deleteResponse = await bulkDeleteRecordings([invalidRecordingIds]);
|
const response = await bulkDeleteRecordings([invalidRecordingIds]);
|
||||||
|
|
||||||
expect(deleteResponse.status).toBe(422);
|
expectValidationError(response, 'recordingIds.0', 'recordingId does not follow the expected format');
|
||||||
expect(deleteResponse.body).toMatchObject({
|
|
||||||
details: [
|
|
||||||
{
|
|
||||||
message: 'recordingId does not follow the expected format'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
error: 'Unprocessable Entity',
|
|
||||||
message: 'Invalid request'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject an array containing empty strings after sanitization', async () => {
|
it('should reject an array containing empty strings after sanitization', async () => {
|
||||||
const invalidRecordingIds = ['', ' '];
|
const invalidRecordingIds = ['', ' '];
|
||||||
const deleteResponse = await bulkDeleteRecordings(invalidRecordingIds);
|
const response = await bulkDeleteRecordings(invalidRecordingIds);
|
||||||
|
|
||||||
expect(deleteResponse.status).toBe(422);
|
expectValidationError(response, 'recordingIds', 'recordingIds must contain at least one item');
|
||||||
expect(deleteResponse.body).toMatchObject({
|
|
||||||
details: [
|
|
||||||
{
|
|
||||||
message: 'recordingIds must contain at least one item'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
error: 'Unprocessable Entity',
|
|
||||||
message: 'Invalid request'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject an array with mixed valid and totally invalid IDs', async () => {
|
it('should reject an array with mixed valid and totally invalid IDs', async () => {
|
||||||
const invalidRecordingIds = ['valid--EG_111--5678', 'invalid--recording.id'];
|
const invalidRecordingIds = ['valid--EG_111--5678', 'invalid--recording.id'];
|
||||||
const deleteResponse = await bulkDeleteRecordings(invalidRecordingIds);
|
const response = await bulkDeleteRecordings(invalidRecordingIds);
|
||||||
|
|
||||||
expect(deleteResponse.status).toBe(422);
|
expectValidationError(response, 'recordingIds.1', 'recordingId does not follow the expected format');
|
||||||
expect(deleteResponse.body).toMatchObject({
|
|
||||||
details: [
|
|
||||||
{
|
|
||||||
message: 'recordingId does not follow the expected format'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
error: 'Unprocessable Entity',
|
|
||||||
message: 'Invalid request'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,15 +3,21 @@ import INTERNAL_CONFIG from '../../src/config/internal-config';
|
|||||||
import { MeetRoom, MeetRoomPreferences } from '../../src/typings/ce';
|
import { MeetRoom, MeetRoomPreferences } from '../../src/typings/ce';
|
||||||
const RECORDINGS_PATH = `${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings`;
|
const RECORDINGS_PATH = `${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings`;
|
||||||
|
|
||||||
export const expectErrorResponse = (
|
const expectErrorResponse = (
|
||||||
response: any,
|
response: any,
|
||||||
status = 422,
|
status = 422,
|
||||||
error = 'Unprocessable Entity',
|
error = 'Unprocessable Entity',
|
||||||
message = 'Invalid request',
|
message = 'Invalid request',
|
||||||
details: Array<{ field?: string; message: string }>
|
details?: Array<{ field?: string; message: string }>
|
||||||
) => {
|
) => {
|
||||||
expect(response.status).toBe(status);
|
expect(response.status).toBe(status);
|
||||||
expect(response.body).toMatchObject({ error, message });
|
expect(response.body).toMatchObject({ error, message });
|
||||||
|
|
||||||
|
if (details === undefined) {
|
||||||
|
expect(response.body.details).toBeUndefined();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
expect(Array.isArray(response.body.details)).toBe(true);
|
expect(Array.isArray(response.body.details)).toBe(true);
|
||||||
expect(response.body.details).toEqual(
|
expect(response.body.details).toEqual(
|
||||||
expect.arrayContaining(
|
expect.arrayContaining(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user