Skip to content

Commit

Permalink
Trim whitespaces in name and starting message while creating bots. (#225
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chinmoy12c authored Sep 15, 2023
1 parent cdd400d commit a490eaf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/modules/bot/bot.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,17 @@ describe('BotService', () => {
.toThrowError(new ConflictException("Bot already exists with the following name or starting message!"));
});

it('create bot trims bot name properly', async () => {
const mockCreateBotDtoCopy: CreateBotDto & { ownerID: string; ownerOrgID: string } = JSON.parse(JSON.stringify(mockCreateBotDto));
mockCreateBotDtoCopy.name = ' testBotExistingName ';
expect(botService.create(mockCreateBotDtoCopy, mockFile)).rejects
.toThrowError(new ConflictException("Bot already exists with the following name or starting message!"));
const mockCreateBotDtoCopy2: CreateBotDto & { ownerID: string; ownerOrgID: string } = JSON.parse(JSON.stringify(mockCreateBotDto));
mockCreateBotDtoCopy2.startingMessage = ' testBotExistingStartingMessage';
expect(botService.create(mockCreateBotDtoCopy2, mockFile)).rejects
.toThrowError(new ConflictException("Bot already exists with the following name or starting message!"));
});

it('get bot all data test', async () => {
fetchMock.getOnce(`${configService.get<string>('MINIO_GET_SIGNED_FILE_URL')}?fileName=testImageFile`,
'testImageUrl'
Expand Down
7 changes: 5 additions & 2 deletions src/modules/bot/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ export class BotService {
const startTime = performance.now();
this.logger.log(`BotService::create: Called with bot name ${data.name}.`);
// Check for unique name
const name = data.name;
const startingMessage = data.startingMessage;
if (!data.name || !data.startingMessage) {
throw new BadRequestException('Bot name is required!');
}
const name = data.name.trim();
const startingMessage = data.startingMessage.trim();
const alreadyExists = await this.prisma.bot.findFirst({
where: {
OR: [
Expand Down

0 comments on commit a490eaf

Please sign in to comment.