Skip to content
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

Merged
merged 2 commits into from
Jul 18, 2023
Merged

Conversation

nunogois
Copy link
Member

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!

@sonatype-lift
Copy link

sonatype-lift bot commented Jul 17, 2023

Sonatype Lift is retiring

Sonatype 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.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@vercel
Copy link

vercel bot commented Jul 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Jul 17, 2023 4:57pm
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Jul 17, 2023 4:57pm

Copy link
Contributor

@gastonfournier gastonfournier left a 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 😅)

Comment on lines 71 to 93
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();
});
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 34f9b6c

Comment on lines 95 to 117
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();
});
Copy link
Contributor

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

Copy link
Member Author

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*",
Copy link
Contributor

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 ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 34f9b6c

@nunogois nunogois merged commit 3b20978 into main Jul 18, 2023
10 checks passed
@nunogois nunogois deleted the test-slack-app branch July 18, 2023 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants