Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sangeetha5491 committed Jul 20, 2023
1 parent 9e416d4 commit 5b368f6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/hooks/pre-undeploy-event-reg.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ const {
} = require('./utils/hook-utils')

module.exports = async function ({ appConfig }) {
await undeployRegistration({ appConfig }, 'pre-undeploy-event-reg')
await undeployRegistration({ appConfig })
}
11 changes: 5 additions & 6 deletions src/hooks/utils/hook-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,25 @@ async function deployRegistration ({ appConfig: { events, project } }, expectedD
* @param {object} appConfigRoot.appConfig - Object containing events and project details
* @param {object} appConfigRoot.appConfig.project - Project details from the .aio file
* @param {object} appConfigRoot.appConfig.events - Events registrations that are part of the app.config.yaml file
* @param {string} hookType - pre-deploy-event-reg or post-deploy-event-reg hook values
*/
async function undeployRegistration ({ appConfig: { events, project } }, hookType) {
async function undeployRegistration ({ appConfig: { events, project } }) {
if (!project) {
throw new Error(
`No project found, skipping event registration in ${hookType} hook`)
'No project found, skipping deletion of event registrations')
}
if (!events) {
console.log(`No events to delete, skipping deletion of event registrations in ${hookType} hook`)
console.log('No events to delete, skipping deletion of event registrations')
return
}
const eventsSDK = await initEventsSdk(project)
if (!eventsSDK.eventsClient) {
throw new Error(
`Events SDK could not be initialised correctly. Skipping event registration in ${hookType} hook`)
'Events SDK could not be initialised correctly. Skipping deletion of event registrations')
}
const registrationsFromConfig = events.registrations
const registrationsFromWorkspace = await getAllRegistrationsForWorkspace(eventsSDK, project)
if (Object.keys(registrationsFromWorkspace).length === 0) {
console.log(`No events to delete, skipping deletion of event registrations in ${hookType} hook`)
console.log('No events to delete, skipping deletion of event registrations')
return
}
for (const registrationName in registrationsFromConfig) {
Expand Down
4 changes: 2 additions & 2 deletions test/hooks/pre-undeploy-event-reg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('pre undeploy event registration hook interfaces', () => {
test('no project error', async () => {
const hook = require('../../src/hooks/pre-undeploy-event-reg')
expect(typeof hook).toBe('function')
await expect(hook({ appConfig: {} })).rejects.toThrowError(new Error('No project found, skipping event registration in pre-undeploy-event-reg hook'))
await expect(hook({ appConfig: {} })).rejects.toThrowError(new Error('No project found, skipping deletion of event registrations'))
})

test('no events should return without error', async () => {
Expand All @@ -64,7 +64,7 @@ describe('pre undeploy event registration hook interfaces', () => {
process.env = mock.data.dotEnvMissingProviderMetadataToProviderIdMapping
getToken.mockReturnValue('accessToken')
eventsSdk.init.mockResolvedValue(undefined)
await expect(hook({ appConfig: { project: mock.data.sampleProject, events: mock.data.sampleEvents } })).rejects.toThrowError(new Error('Events SDK could not be initialised correctly. Skipping event registration in pre-undeploy-event-reg hook'))
await expect(hook({ appConfig: { project: mock.data.sampleProject, events: mock.data.sampleEvents } })).rejects.toThrowError(new Error('Events SDK could not be initialised correctly. Skipping deletion of event registrations'))
})

test('no event registrations in workspace to return without error', async () => {
Expand Down

0 comments on commit 5b368f6

Please sign in to comment.