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