From 7e9322bc94a89d0806bcdcc882117c0df1da8652 Mon Sep 17 00:00:00 2001 From: Ryanwalker277 Date: Tue, 26 Sep 2023 23:52:39 +0530 Subject: [PATCH] Enhancement: Modified Botservice.remove to return deleted bot ids --- src/modules/bot/bot.service.spec.ts | 8 ++++++++ src/modules/bot/bot.service.ts | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/modules/bot/bot.service.spec.ts b/src/modules/bot/bot.service.spec.ts index 72803b8..1fcdca5 100644 --- a/src/modules/bot/bot.service.spec.ts +++ b/src/modules/bot/bot.service.spec.ts @@ -735,4 +735,12 @@ describe('BotService', () => { deletedIds = []; fetchMock.restore(); }); + it('should delete bots by IDs and return the deleted bot IDs', async () => { + jest.spyOn(botService, 'remove').mockResolvedValue(['id1', 'id2']) + fetchMock.delete(`${configService.get('UCI_CORE_BASE_URL')}${configService.get('CAFFINE_INVALIDATE_ENDPOINT')}`, + true + ); + deletedIds = await botService.remove({ids: ['id1','id2'], endDate: null}); + expect(deletedIds).toEqual(['id1','id2']); + }); }); diff --git a/src/modules/bot/bot.service.ts b/src/modules/bot/bot.service.ts index 36b9375..8f7376a 100644 --- a/src/modules/bot/bot.service.ts +++ b/src/modules/bot/bot.service.ts @@ -596,6 +596,7 @@ export class BotService { } const allBots = await this.findAllUnresolved(); + const deletedBots: string[] = []; const requiredBotIds: string[] = [], requiredServiceIds: string[] = [], requiredUserIds: string[] = [], requiredLogicIds: string[] = [], requiredTransformerConfigIds: string[] = []; @@ -607,6 +608,7 @@ export class BotService { (endDate && (parsedEndDate.getTime() >= currentParsedEndDate.getTime()) && botIds.size == 0) || (botIds.has(bot.id) && (endDate && (parsedEndDate.getTime() >= currentParsedEndDate.getTime()))) ) { + deletedBots.push(bot.id); requiredBotIds.push(bot.id); if (bot.logicIDs.length > 0) { requiredLogicIds.push(bot.logicIDs[0].id); @@ -663,7 +665,8 @@ export class BotService { return Promise.all(deletePromises) .then(() => { - return this.invalidateTransactionLayerCache(); + this.invalidateTransactionLayerCache(); + return deletedBots; }) .catch((err) => { throw err;