backend: update recording location header to use API_BASE_PATH_V1 and update test for validating location header
This commit is contained in:
parent
cdcafd22d0
commit
66d63378fb
@ -20,7 +20,7 @@ export const startRecording = async (req: Request, res: Response) => {
|
|||||||
const recordingInfo = await recordingService.startRecording(roomId);
|
const recordingInfo = await recordingService.startRecording(roomId);
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
'Location',
|
'Location',
|
||||||
`${req.protocol}://${req.get('host')}${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings/${recordingInfo.recordingId}`
|
`${req.protocol}://${req.get('host')}${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${recordingInfo.recordingId}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(201).json(recordingInfo);
|
return res.status(201).json(recordingInfo);
|
||||||
@ -114,7 +114,7 @@ export const stopRecording = async (req: Request, res: Response) => {
|
|||||||
const recordingInfo = await recordingService.stopRecording(recordingId);
|
const recordingInfo = await recordingService.stopRecording(recordingId);
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
'Location',
|
'Location',
|
||||||
`${req.protocol}://${req.get('host')}${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings/${recordingId}`
|
`${req.protocol}://${req.get('host')}${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${recordingId}`
|
||||||
);
|
);
|
||||||
return res.status(202).json(recordingInfo);
|
return res.status(202).json(recordingInfo);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -182,15 +182,12 @@ const expectObjectFields = (obj: any, present: string[] = [], absent: string[] =
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Validate recording location header in the response
|
||||||
export const expectValidRecordingLocationHeader = (response: any) => {
|
export const expectValidRecordingLocationHeader = (response: any) => {
|
||||||
// const locationRegex = new RegExp(
|
const locationHeader = response.headers.location;
|
||||||
// `^http://127\\.0\\.0\\.1:\\d+/+${RECORDINGS_PATH.replace(/\//g, '\\/')}/${recordingId}$`
|
expect(locationHeader).toBeDefined();
|
||||||
// );
|
const locationHeaderUrl = new URL(locationHeader);
|
||||||
// expect(response.headers.location).toMatch(locationRegex);
|
expect(locationHeaderUrl.pathname).toBe(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${response.body.recordingId}`);
|
||||||
expect(response.headers.location).toBeDefined();
|
|
||||||
expect(response.headers.location).toContain('127.0.0.1');
|
|
||||||
expect(response.headers.location).toContain(RECORDINGS_PATH);
|
|
||||||
expect(response.headers.location).toContain(response.body.recordingId);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,7 +323,12 @@ export const expectSuccessRecordingMediaResponse = (
|
|||||||
export const expectValidStartRecordingResponse = (response: any, roomId: string) => {
|
export const expectValidStartRecordingResponse = (response: any, roomId: string) => {
|
||||||
expect(response.status).toBe(201);
|
expect(response.status).toBe(201);
|
||||||
expect(response.body).toHaveProperty('recordingId');
|
expect(response.body).toHaveProperty('recordingId');
|
||||||
|
|
||||||
|
expectValidRecordingLocationHeader(response);
|
||||||
|
|
||||||
const recordingId = response.body.recordingId;
|
const recordingId = response.body.recordingId;
|
||||||
|
expect(recordingId).toBeDefined();
|
||||||
|
|
||||||
expect(recordingId).toContain(roomId);
|
expect(recordingId).toContain(roomId);
|
||||||
expect(response.body).toHaveProperty('roomId', roomId);
|
expect(response.body).toHaveProperty('roomId', roomId);
|
||||||
expect(response.body).toHaveProperty('startDate');
|
expect(response.body).toHaveProperty('startDate');
|
||||||
@ -346,6 +348,8 @@ export const expectValidStopRecordingResponse = (response: any, recordingId: str
|
|||||||
expect(response.body).toHaveProperty('filename');
|
expect(response.body).toHaveProperty('filename');
|
||||||
expect(response.body).toHaveProperty('startDate');
|
expect(response.body).toHaveProperty('startDate');
|
||||||
expect(response.body).toHaveProperty('duration', expect.any(Number));
|
expect(response.body).toHaveProperty('duration', expect.any(Number));
|
||||||
|
|
||||||
|
expectValidRecordingLocationHeader(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const expectValidGetRecordingResponse = (
|
export const expectValidGetRecordingResponse = (
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { errorRoomNotFound } from '../../../../src/models/error.model.js';
|
|||||||
import { MeetRoom } from '../../../../src/typings/ce/index.js';
|
import { MeetRoom } from '../../../../src/typings/ce/index.js';
|
||||||
import {
|
import {
|
||||||
expectValidationError,
|
expectValidationError,
|
||||||
expectValidRecordingLocationHeader,
|
|
||||||
expectValidStartRecordingResponse,
|
expectValidStartRecordingResponse,
|
||||||
expectValidStopRecordingResponse
|
expectValidStopRecordingResponse
|
||||||
} from '../../../helpers/assertion-helpers.js';
|
} from '../../../helpers/assertion-helpers.js';
|
||||||
@ -56,7 +55,6 @@ describe('Recording API Tests', () => {
|
|||||||
const recordingId = response.body.recordingId;
|
const recordingId = response.body.recordingId;
|
||||||
expectValidStartRecordingResponse(response, room.roomId);
|
expectValidStartRecordingResponse(response, room.roomId);
|
||||||
|
|
||||||
expectValidRecordingLocationHeader(response);
|
|
||||||
const stopResponse = await stopRecording(recordingId, moderatorCookie);
|
const stopResponse = await stopRecording(recordingId, moderatorCookie);
|
||||||
expectValidStopRecordingResponse(stopResponse, recordingId, room.roomId);
|
expectValidStopRecordingResponse(stopResponse, recordingId, room.roomId);
|
||||||
});
|
});
|
||||||
@ -66,8 +64,6 @@ describe('Recording API Tests', () => {
|
|||||||
const recordingId = response.body.recordingId;
|
const recordingId = response.body.recordingId;
|
||||||
expectValidStartRecordingResponse(response, room.roomId);
|
expectValidStartRecordingResponse(response, room.roomId);
|
||||||
|
|
||||||
expectValidRecordingLocationHeader(response);
|
|
||||||
|
|
||||||
const storageService = container.get(MeetStorageService);
|
const storageService = container.get(MeetStorageService);
|
||||||
|
|
||||||
const recSecrets = await storageService.getAccessRecordingSecrets(recordingId);
|
const recSecrets = await storageService.getAccessRecordingSecrets(recordingId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user