Skip to content

Commit e142a7f

Browse files
authored
fix: return user friend error if room name is invalid (#40)
1 parent d0f97f4 commit e142a7f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/modules/call/call.controller.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { CallUseCase } from './call.usecase';
1313
import { JoinCallDto, JoinCallResponseDto } from './dto/join-call.dto';
1414
import { LeaveCallDto } from './dto/leave-call.dto';
1515
import { createMockUserToken, mockUserPayload } from './fixtures';
16+
import { v4 } from 'uuid';
1617

1718
describe('Testing Call Endpoints', () => {
1819
let callController: CallController;
1920
let callUseCase: DeepMocked<CallUseCase>;
2021
let roomService: DeepMocked<RoomService>;
2122

22-
const mockRoomId = 'test-room-id';
23+
const mockRoomId = v4();
2324
const mockJoinCallDto: JoinCallDto = {
2425
name: 'Test User',
2526
lastName: 'Smith',
@@ -266,6 +267,14 @@ describe('Testing Call Endpoints', () => {
266267
});
267268
expect(result).toEqual(mockJoinCallResponse);
268269
});
270+
271+
it('When joining a call with invalid room name (not UUID), then it should throw', async () => {
272+
callUseCase.joinCall.mockResolvedValue(mockJoinCallResponse);
273+
274+
await expect(
275+
callController.joinCall('invalid room name', null, mockJoinCallDto),
276+
).rejects.toThrow(BadRequestException);
277+
});
269278
});
270279

271280
describe('Getting users in a call', () => {

src/modules/call/call.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { CallUseCase } from './call.usecase';
3333
import { CreateCallResponseDto } from './dto/create-call.dto';
3434
import { JoinCallDto, JoinCallResponseDto } from './dto/join-call.dto';
3535
import { LeaveCallDto } from './dto/leave-call.dto';
36+
import { isUUID } from 'class-validator';
3637

3738
@ApiTags('Call')
3839
@Controller('call')
@@ -118,6 +119,10 @@ export class CallController {
118119
@User() user: UserTokenData['payload'],
119120
@Body() joinCallDto?: JoinCallDto,
120121
): Promise<JoinCallResponseDto> {
122+
if (!isUUID(roomId)) {
123+
throw new BadRequestException('Room id is not valid');
124+
}
125+
121126
const { uuid, email } = user || {};
122127
const isUserAnonymous =
123128
!user || !!joinCallDto?.anonymousId || joinCallDto?.anonymous === true;

0 commit comments

Comments
 (0)