-
-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add some basic tests to the new slack app #4259
Conversation
Sonatype Lift is retiringSonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, just some comments but more tests don't hurt (well, until they do, because your build slows down 😅)
src/lib/addons/slack-app.test.ts
Outdated
test('Should call Slack API for archived toggle', async () => { | ||
const addon = new SlackAppAddon({ | ||
getLogger: noLogger, | ||
unleashUrl: 'http://some-url.com', | ||
}); | ||
const event: IEvent = { | ||
id: 2, | ||
createdAt: new Date(), | ||
type: FEATURE_ARCHIVED, | ||
createdBy: 'some@user.com', | ||
project: 'default', | ||
featureName: 'some-toggle', | ||
data: { | ||
name: 'some-toggle', | ||
}, | ||
tags: [{ type: 'slack', value: 'general' }], | ||
}; | ||
|
||
await addon.handleEvent(event, { accessToken }); | ||
expect(slackApiCalls.length).toBe(1); | ||
expect(slackApiCalls[0].channel).toBe(1); | ||
expect(slackApiCalls[0]).toMatchSnapshot(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not needed, AFAIK the logic to deliver an event to an addon is elsewhere. SlackAppAddon doesn't have any rejection logic. Doesn't hurt to have more tests though, but just mentioning it :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, but to be fair these tests are there in the old slack addon. I guess they are there simply for the extra snapshots. I can remove these for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 34f9b6c
src/lib/addons/slack-app.test.ts
Outdated
test(`Should call Slack API for toggled environment`, async () => { | ||
const addon = new SlackAppAddon({ | ||
getLogger: noLogger, | ||
unleashUrl: 'http://some-url.com', | ||
}); | ||
const event: IEvent = { | ||
id: 3, | ||
createdAt: new Date(), | ||
type: FEATURE_ENVIRONMENT_DISABLED, | ||
createdBy: 'some@user.com', | ||
project: 'default', | ||
featureName: 'some-toggle', | ||
data: { | ||
name: 'some-toggle', | ||
}, | ||
tags: [{ type: 'slack', value: 'general' }], | ||
}; | ||
|
||
await addon.handleEvent(event, { accessToken }); | ||
expect(slackApiCalls.length).toBe(1); | ||
expect(slackApiCalls[0].channel).toBe(1); | ||
expect(slackApiCalls[0]).toMatchSnapshot(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, similar comment, unless there's something about the mapping that you're covering here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 34f9b6c
}, | ||
], | ||
"channel": 2, | ||
"text": "some@user.com *disabled* <http://some-url.com/projects/default/features/some-toggle|some-toggle> in *undefined* environment in project *default*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add environment to one of the tests ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 34f9b6c
https://linear.app/unleash/issue/2-1244/write-some-tests-for-the-new-slack-app-addon
Pretty self-explanatory. These are based on the tests we have for the other addons.
If you're reading this and have any suggestions of tests we could add at this stage, please let me know.
Thanks!