Skip to content

Commit

Permalink
Enhancement: Modified Botservice.remove to return deleted bot ids
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanWalker277 committed Sep 26, 2023
1 parent a490eaf commit 7e9322b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/modules/bot/bot.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>('UCI_CORE_BASE_URL')}${configService.get<string>('CAFFINE_INVALIDATE_ENDPOINT')}`,
true
);
deletedIds = await botService.remove({ids: ['id1','id2'], endDate: null});
expect(deletedIds).toEqual(['id1','id2']);
});
});
5 changes: 4 additions & 1 deletion src/modules/bot/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -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);
Expand Down Expand Up @@ -663,7 +665,8 @@ export class BotService {

return Promise.all(deletePromises)
.then(() => {
return this.invalidateTransactionLayerCache();
this.invalidateTransactionLayerCache();
return deletedBots;
})
.catch((err) => {
throw err;
Expand Down

0 comments on commit 7e9322b

Please sign in to comment.