Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nunogois committed Sep 20, 2024
1 parent f07cc2e commit c9bd071
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 53 deletions.
12 changes: 6 additions & 6 deletions src/lib/addons/__snapshots__/datadog.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Datadog integration Should call datadog webhook for archived toggle 1`] = `"{"text":"%%% \\n *[email protected]* archived *some-toggle* in project ** \\n %%% ","title":"Unleash notification update"}"`;
exports[`Datadog integration Should call datadog webhook for archived toggle 1`] = `"{"text":"%%% \\n **[email protected]** archived **some-toggle** in project **** \\n %%% ","title":"Unleash notification update"}"`;

exports[`Datadog integration Should call datadog webhook for archived toggle with project info 1`] = `"{"text":"%%% \\n *[email protected]* archived *some-toggle* in project *[some-project](http://some-url.com/projects/some-project)* \\n %%% ","title":"Unleash notification update"}"`;
exports[`Datadog integration Should call datadog webhook for archived toggle with project info 1`] = `"{"text":"%%% \\n **[email protected]** archived **some-toggle** in project **[some-project](http://some-url.com/projects/some-project)** \\n %%% ","title":"Unleash notification update"}"`;

exports[`Datadog integration Should call datadog webhook 1`] = `"{"text":"%%% \\n *[email protected]* created *[some-toggle](http://some-url.com/projects//features/some-toggle)* in project ** \\n %%% ","title":"Unleash notification update"}"`;
exports[`Datadog integration Should call datadog webhook 1`] = `"{"text":"%%% \\n **[email protected]** created **[some-toggle](http://some-url.com/projects//features/some-toggle)** in project **** \\n %%% ","title":"Unleash notification update"}"`;

exports[`Datadog integration Should call datadog webhook for toggled environment 1`] = `"{"text":"%%% \\n *[email protected]* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update"}"`;
exports[`Datadog integration Should call datadog webhook for toggled environment 1`] = `"{"text":"%%% \\n **[email protected]** disabled **[some-toggle](http://some-url.com/projects/default/features/some-toggle)** for the **development** environment in project **[default](http://some-url.com/projects/default)** \\n %%% ","title":"Unleash notification update"}"`;

exports[`Datadog integration Should call datadog webhook with JSON when template set 1`] = `"{"text":"{\\n \\"event\\": \\"feature-created\\",\\n \\"createdBy\\": \\"some@user.com\\"\\n}","title":"Unleash notification update"}"`;

exports[`Datadog integration Should include customHeaders in headers when calling service 1`] = `"{"text":"%%% \\n *[email protected]* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update"}"`;
exports[`Datadog integration Should include customHeaders in headers when calling service 1`] = `"{"text":"%%% \\n **[email protected]** disabled **[some-toggle](http://some-url.com/projects/default/features/some-toggle)** for the **development** environment in project **[default](http://some-url.com/projects/default)** \\n %%% ","title":"Unleash notification update"}"`;

exports[`Datadog integration Should include customHeaders in headers when calling service 2`] = `
{
Expand All @@ -20,7 +20,7 @@ exports[`Datadog integration Should include customHeaders in headers when callin
}
`;

exports[`Datadog integration Should not include source_type_name when included in the config 1`] = `"{"text":"%%% \\n *[email protected]* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update","source_type_name":"my-custom-source-type"}"`;
exports[`Datadog integration Should not include source_type_name when included in the config 1`] = `"{"text":"%%% \\n **[email protected]** disabled **[some-toggle](http://some-url.com/projects/default/features/some-toggle)** for the **development** environment in project **[default](http://some-url.com/projects/default)** \\n %%% ","title":"Unleash notification update","source_type_name":"my-custom-source-type"}"`;

exports[`Datadog integration Should not include source_type_name when included in the config 2`] = `
{
Expand Down

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/lib/addons/__snapshots__/slack.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Slack integration Should call slack webhook 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"*[email protected]* created *<http://some-url.com/projects/default/features/some-toggle|some-toggle>* in project *<http://some-url.com/projects/default|default>*","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;
exports[`Slack integration Should call slack webhook 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"**[email protected]** created **<http://some-url.com/projects/default/features/some-toggle|some-toggle>** in project **<http://some-url.com/projects/default|default>**","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;

exports[`Slack integration Should call slack webhook for archived toggle 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"*[email protected]* archived *some-toggle* in project **","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects//archive"}]}]}"`;
exports[`Slack integration Should call slack webhook for archived toggle 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"**[email protected]** archived **some-toggle** in project ****","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects//archive"}]}]}"`;

exports[`Slack integration Should call slack webhook for archived toggle with project info 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"*[email protected]* archived *some-toggle* in project *<http://some-url.com/projects/some-project|some-project>*","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects/some-project/archive"}]}]}"`;
exports[`Slack integration Should call slack webhook for archived toggle with project info 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"**[email protected]** archived **some-toggle** in project **<http://some-url.com/projects/some-project|some-project>**","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects/some-project/archive"}]}]}"`;

exports[`Slack integration Should call webhook for toggled environment 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"*[email protected]* disabled *<http://some-url.com/projects/default/features/some-toggle|some-toggle>* for the *development* environment in project *<http://some-url.com/projects/default|default>*","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;
exports[`Slack integration Should call webhook for toggled environment 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"**[email protected]** disabled **<http://some-url.com/projects/default/features/some-toggle|some-toggle>** for the **development** environment in project **<http://some-url.com/projects/default|default>**","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;

exports[`Slack integration Should include custom headers from parameters in call to service 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"*[email protected]* disabled *<http://some-url.com/projects/default/features/some-toggle|some-toggle>* for the *development* environment in project *<http://some-url.com/projects/default|default>*","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;
exports[`Slack integration Should include custom headers from parameters in call to service 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"**[email protected]** disabled **<http://some-url.com/projects/default/features/some-toggle|some-toggle>** for the **development** environment in project **<http://some-url.com/projects/default|default>**","channel":"#general","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;

exports[`Slack integration Should include custom headers from parameters in call to service 2`] = `
{
Expand Down
10 changes: 5 additions & 5 deletions src/lib/addons/__snapshots__/teams.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Teams integration Should call teams webhook 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"*[email protected]* created *[some-toggle](http://some-url.com/projects//features/some-toggle)* in project **","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-created"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects//features/some-toggle"}]}]}"`;
exports[`Teams integration Should call teams webhook 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"**[email protected]** created **[some-toggle](http://some-url.com/projects//features/some-toggle)** in project ****","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-created"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects//features/some-toggle"}]}]}"`;

exports[`Teams integration Should call teams webhook for archived toggle 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"*[email protected]* archived *some-toggle* in project **","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-archived"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects//archive"}]}]}"`;
exports[`Teams integration Should call teams webhook for archived toggle 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"**[email protected]** archived **some-toggle** in project ****","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-archived"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects//archive"}]}]}"`;

exports[`Teams integration Should call teams webhook for archived toggle with project info 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"*[email protected]* archived *some-toggle* in project *[some-project](http://some-url.com/projects/some-project)*","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-archived"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects/some-project/archive"}]}]}"`;
exports[`Teams integration Should call teams webhook for archived toggle with project info 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"**[email protected]** archived **some-toggle** in project **[some-project](http://some-url.com/projects/some-project)**","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-archived"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects/some-project/archive"}]}]}"`;

exports[`Teams integration Should call teams webhook for toggled environment 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"*[email protected]* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)*","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-environment-disabled"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;
exports[`Teams integration Should call teams webhook for toggled environment 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"**[email protected]** disabled **[some-toggle](http://some-url.com/projects/default/features/some-toggle)** for the **development** environment in project **[default](http://some-url.com/projects/default)**","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-environment-disabled"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;

exports[`Teams integration Should include custom headers in call to teams 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"*[email protected]* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)*","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-environment-disabled"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;
exports[`Teams integration Should include custom headers in call to teams 1`] = `"{"themeColor":"0076D7","summary":"Message","sections":[{"activityTitle":"**[email protected]** disabled **[some-toggle](http://some-url.com/projects/default/features/some-toggle)** for the **development** environment in project **[default](http://some-url.com/projects/default)**","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"[email protected]"},{"name":"Action","value":"feature-environment-disabled"}]}],"potentialAction":[{"@type":"OpenUri","name":"Go to feature","targets":[{"os":"default","uri":"http://some-url.com/projects/default/features/some-toggle"}]}]}"`;

exports[`Teams integration Should include custom headers in call to teams 2`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/addons/__snapshots__/webhook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
exports[`Webhook integration should allow for eventJson and eventMarkdown in bodyTemplate 1`] = `
"{
"json": "{\\"id\\":1,\\"createdAt\\":\\"2024-07-24T00:00:00.000Z\\",\\"createdByUserId\\":-1337,\\"type\\":\\"feature-created\\",\\"createdBy\\":\\"some@user.com\\",\\"featureName\\":\\"some-toggle\\",\\"project\\":\\"default\\",\\"data\\":{\\"name\\":\\"some-toggle\\",\\"enabled\\":false,\\"strategies\\":[{\\"name\\":\\"default\\"}]}}",
"markdown": "*[email protected]* created *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* in project *[default](http://some-url.com/projects/default)*"
"markdown": "**[email protected]** created **[some-toggle](http://some-url.com/projects/default/features/some-toggle)** in project **[default](http://some-url.com/projects/default)**"
}"
`;
2 changes: 1 addition & 1 deletion src/lib/addons/feature-event-formatter-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export enum LinkStyle {
MD = 1,
}

const bold = (text?: string) => (text ? `**${text}**` : '');
export const bold = (text?: string) => (text ? `**${text}**` : '');

const EVENT_MAP: Record<string, IEventData> = {
[ADDON_CONFIG_CREATED]: {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/addons/slack-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../types';
import type { IntegrationEventsService } from '../services';
import type { Logger } from '../logger';
import { bold } from './feature-event-formatter-md';

const slackApiCalls: ChatPostMessageArguments[] = [];

Expand Down Expand Up @@ -271,8 +272,7 @@ describe('SlackAppAddon', () => {
event: serializeDates(eventWith2Tags),
details: {
channels: ['general', 'another-channel-1', 'another-channel-2'],
message:
'*[email protected]* enabled *<http://some-url.com/projects/default/features/some-toggle|some-toggle>* for the *development* environment in project *<http://some-url.com/projects/default|default>*',
message: `${bold('[email protected]')} enabled ${bold('<http://some-url.com/projects/default/features/some-toggle|some-toggle>')} for the ${bold('development')} environment in project ${bold('<http://some-url.com/projects/default|default>')}`,
},
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/addons/slack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SYSTEM_USER_ID,
} from '../types';
import type { IntegrationEventsService } from '../services';
import { bold } from './feature-event-formatter-md';

let fetchRetryCalls: any[] = [];
const registerEventMock = jest.fn();
Expand Down Expand Up @@ -338,8 +339,7 @@ describe('Slack integration', () => {
url: parameters.url,
channels: ['general'],
username: 'Unleash',
message:
'*[email protected]* disabled *<http://some-url.com/projects/default/features/some-toggle|some-toggle>* for the *development* environment in project *<http://some-url.com/projects/default|default>*',
message: `${bold('[email protected]')} disabled ${bold('<http://some-url.com/projects/default/features/some-toggle|some-toggle>')} for the ${bold('development')} environment in project ${bold('<http://some-url.com/projects/default|default>')}`,
},
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/lib/addons/teams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SYSTEM_USER_ID,
} from '../types';
import type { IntegrationEventsService } from '../services';
import { bold } from './feature-event-formatter-md';

let fetchRetryCalls: any[];
const registerEventMock = jest.fn();
Expand Down Expand Up @@ -231,7 +232,7 @@ describe('Teams integration', () => {
summary: 'Message',
sections: [
{
activityTitle: `*${event.createdBy}* disabled *[${event.featureName}](${ARGS.unleashUrl}/projects/${event.project}/features/${event.featureName})* for the *${event.environment}* environment in project *[${event.project}](${ARGS.unleashUrl}/projects/${event.project})*`,
activityTitle: `${bold(event.createdBy)} disabled ${bold(`[${event.featureName}](${ARGS.unleashUrl}/projects/${event.project}/features/${event.featureName})`)} for the ${bold(event.environment)} environment in project ${bold(`[${event.project}](${ARGS.unleashUrl}/projects/${event.project})`)}`,
activitySubtitle: `Unleash notification update`,
facts: [
{
Expand Down

0 comments on commit c9bd071

Please sign in to comment.