Skip to content

Commit

Permalink
Add test cases for notification modify endpoint. (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmoy12c authored Jul 18, 2024
1 parent be90edc commit 25b2de7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion src/modules/bot/bot.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const MockPrismaService = {
transformerConfig: {
deleteMany: (filter) => {
deletedIds.push({'transformerConfig': filter.where.id.in});
}
},
update: jest.fn(),
},
conversationLogic: {
deleteMany: (filter) => {
Expand Down Expand Up @@ -879,6 +880,38 @@ describe('BotService', () => {
fetchMock.restore();
});

it('modifyNotification works as expected', async () => {
fetchMock.getOnce(`${configService.get<string>('MINIO_GET_SIGNED_FILE_URL')}/?fileName=testImageFile`,
'testImageUrl'
);
fetchMock.deleteOnce(`${configService.get<string>('UCI_CORE_BASE_URL')}${configService.get<string>('CAFFINE_INVALIDATE_ENDPOINT')}`,
true
);
fetchMock.deleteOnce(`${configService.get<string>('ORCHESTRATOR_BASE_URL')}${configService.get<string>('CAFFINE_INVALIDATE_ENDPOINT')}`,
true
);
jest.spyOn(MockPrismaService.transformerConfig, 'update').mockImplementation((filter) => {
const botCopy = JSON.parse(JSON.stringify(mockBotsDb[0]));
botCopy.logicIDs[0].transformers[0].meta.body = 'myDescription';
botCopy.logicIDs[0].transformers[0].meta.title = 'myTitle';
expect(filter).toStrictEqual({
where: {
id: 'testTransformerId',
},
data: {
meta: botCopy.logicIDs[0].transformers[0].meta,
},
});
});
await botService.modifyNotification('existingBot', 'myTitle', 'myDescription');
});

it ('modifyNotification throws for non existing bot', () => {
expect(botService.modifyNotification('testBotIdNotExisting', 'myTitle', 'myDescription'))
.rejects
.toThrowError(new BadRequestException(`Bot with id: testBotIdNotExisting does not exist!`));
});

it('bot scheduling works as expected', async () => {
const futureDate = new Date(Date.now() + 100000);
jest.spyOn(MockSchedulerRegistry, 'addCronJob').mockImplementation((id: string, cron) => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/bot/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ export class BotService {

async modifyNotification(botId: string, title?: string, description?: string) {
const requiredBot = await this.findOne(botId);
if (!botId) {
if (!requiredBot) {
throw new BadRequestException(`Bot with id: ${botId} does not exist!`);
}
const requiredTransformer = requiredBot?.logicIDs?.[0]?.transformers?.[0];
Expand Down

0 comments on commit 25b2de7

Please sign in to comment.