Skip to content

Commit

Permalink
Merge pull request #221 from samagra-comms/develop
Browse files Browse the repository at this point in the history
Develop Merge
  • Loading branch information
chinmoy12c authored Aug 31, 2023
2 parents 578abe8 + f3420bd commit 5c577eb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
with:
context: "."
push: true
tags: samagragovernance/uci-apis:${{ steps.vars.outputs.tag }}
tags: samagragovernance/uci-apis:${{ steps.vars.outputs.tag }}, latest
8 changes: 6 additions & 2 deletions src/modules/bot/bot.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,18 @@ describe('BotService', () => {
})

it('bot report fetches data correctly', async () => {
const urlRegex = /^http:\/\/uci_core_base_urltestbotreportendpoint\/\?botId=testBotId&createdAt=\d+&limit=10&nextPage=testNextPage$/;
fetchMock.getOnce(`${configService.get<string>('MINIO_GET_SIGNED_FILE_URL')}/?fileName=testImageFile`,
'testImageUrl'
);
fetchMock.getOnce(
`${configService.get<string>('UCI_CORE_BASE_URL')}${configService.get<string>('BROADCAST_BOT_REPORT_ENDPOINT')}?botId=testBotId&limit=10&nextPage=testNextPage`,
urlRegex,
true
);
await botService.getBroadcastReport('testBotId', 10, 'testNextPage');
expect(
fetchMock.called(
`${configService.get<string>('UCI_CORE_BASE_URL')}${configService.get<string>('BROADCAST_BOT_REPORT_ENDPOINT')}?botId=testBotId&limit=10&nextPage=testNextPage`
urlRegex
)
).toBe(true);
fetchMock.restore();
Expand Down
22 changes: 19 additions & 3 deletions src/modules/bot/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ export class BotService {
}
}

if (!requiredBot) {
throw new NotFoundException('Bot does not exist!');
}

const requiredData: {
'bot': {
'id': string,
Expand Down Expand Up @@ -571,7 +575,11 @@ export class BotService {
this.logger.error(`Config data missing. UCI_CORE_BASE_URL: ${inbound_base}, BROADCAST_BOT_REPORT_ENDPOINT: ${broadcast_bot_report_endpoint}`)
throw new InternalServerErrorException('Config data missing!');
}
let report_endpoint = `${inbound_base}${broadcast_bot_report_endpoint}?botId=${botId}`;
const broadcastBotData = await this.findOne(botId);
if (!broadcastBotData) {
throw new NotFoundException('Bot does not exist!');
}
let report_endpoint = `${inbound_base}${broadcast_bot_report_endpoint}?botId=${botId}&createdAt=${new Date(broadcastBotData.createdAt).getTime()}`;
if (limit) {
report_endpoint += `&limit=${limit}`;
}
Expand All @@ -580,7 +588,15 @@ export class BotService {
}
this.logger.log(`Calling inbound for report with link: ${report_endpoint}`);
return await fetch(report_endpoint)
.then(resp => resp.json())
.then(resp => resp);
.then(resp => {
if (!resp.ok) {
throw new ServiceUnavailableException('Could not pull data from database!');
}
return resp.json();
})
.then(resp => resp)
.catch(err => {
throw new ServiceUnavailableException('Could not pull data from database!');
});
}
}

0 comments on commit 5c577eb

Please sign in to comment.