Skip to content

Commit

Permalink
Throw error if provider metadata does not have provider id mapping (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
sangeetha5491 authored Oct 11, 2023
1 parent ca705e9 commit 73088af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hooks/utils/hook-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function getEventsOfInterestForRegistration (registration,
const eventsOfInterestCompressed = registration.events_of_interest
eventsOfInterestCompressed.forEach(eventOfInterest => {
const providerId = providerMetadataToProviderIdMapping[eventOfInterest.provider_metadata]
if (!providerId) {
throw new Error(
`No provider id mapping found for provider metadata ${eventOfInterest.provider_metadata}. Skipping event registration`)
}
const eventCodesList = eventOfInterest.event_codes
for (const eventCode of eventCodesList) {
eventsOfInterest.push({
Expand Down
13 changes: 13 additions & 0 deletions test/hooks/post-deploy-event-reg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ describe('post deploy event registration hook interfaces', () => {
await expect(hook({ appConfig: { project: mock.data.sampleProject, events: mock.data.sampleEvents } })).rejects.toThrow(new Error('No environment variables for provider metadata to provider id mappings found.'))
})

test('providerMetadata to providerId missing for some providers', async () => {
const hook = require('../../src/hooks/post-deploy-event-reg')
expect(typeof hook).toBe('function')
process.env = mock.data.dotEnvMissingProviderMetadataToProviderIdMapping
process.env.AIO_events_providermetadata_to_provider_mapping = ''
process.env = {
...mock.data.dotEnvMissingProviderMetadataToProviderIdMapping,
AIO_EVENTS_PROVIDERMETADATA_TO_PROVIDER_MAPPING: 'providerMetadata2:providerId2'
}
getToken.mockReturnValue('accessToken')
await expect(hook({ appConfig: { project: mock.data.sampleProject, events: mock.data.sampleEvents } })).rejects.toThrow(new Error('No provider id mapping found for provider metadata providerMetadata1. Skipping event registration'))
})

test('error in create registration', async () => {
const hook = require('../../src/hooks/post-deploy-event-reg')
expect(typeof hook).toBe('function')
Expand Down

0 comments on commit 73088af

Please sign in to comment.