From c9bd071c079aa3c03edc2ac08590d265715b9d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Fri, 20 Sep 2024 15:03:23 +0100 Subject: [PATCH] test: fix tests --- .../addons/__snapshots__/datadog.test.ts.snap | 12 +-- .../feature-event-formatter-md.test.ts.snap | 90 ++++++++++++------- .../addons/__snapshots__/slack.test.ts.snap | 10 +-- .../addons/__snapshots__/teams.test.ts.snap | 10 +-- .../addons/__snapshots__/webhook.test.ts.snap | 2 +- src/lib/addons/feature-event-formatter-md.ts | 2 +- src/lib/addons/slack-app.test.ts | 4 +- src/lib/addons/slack.test.ts | 4 +- src/lib/addons/teams.test.ts | 3 +- 9 files changed, 84 insertions(+), 53 deletions(-) diff --git a/src/lib/addons/__snapshots__/datadog.test.ts.snap b/src/lib/addons/__snapshots__/datadog.test.ts.snap index 2395873197..2480612ff0 100644 --- a/src/lib/addons/__snapshots__/datadog.test.ts.snap +++ b/src/lib/addons/__snapshots__/datadog.test.ts.snap @@ -1,16 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Datadog integration Should call datadog webhook for archived toggle 1`] = `"{"text":"%%% \\n *some@user.com* archived *some-toggle* in project ** \\n %%% ","title":"Unleash notification update"}"`; +exports[`Datadog integration Should call datadog webhook for archived toggle 1`] = `"{"text":"%%% \\n **some@user.com** 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 *some@user.com* 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 **some@user.com** 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 *some@user.com* 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 **some@user.com** 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 *some@user.com* 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 **some@user.com** 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 *some@user.com* 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 **some@user.com** 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`] = ` { @@ -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 *some@user.com* 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 **some@user.com** 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`] = ` { diff --git a/src/lib/addons/__snapshots__/feature-event-formatter-md.test.ts.snap b/src/lib/addons/__snapshots__/feature-event-formatter-md.test.ts.snap index bf49309fe6..280dfcc9c9 100644 --- a/src/lib/addons/__snapshots__/feature-event-formatter-md.test.ts.snap +++ b/src/lib/addons/__snapshots__/feature-event-formatter-md.test.ts.snap @@ -2,210 +2,240 @@ exports[`Should format specialised text for events when IPs changed 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *remoteAddress* in *production* IPs from empty set of IPs to [127.0.0.1]; constraints from empty set of constraints to [appName is one of (x,y)]", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **remoteAddress** in **production** IPs from empty set of IPs to [127.0.0.1]; constraints from empty set of constraints to [appName is one of (x,y)]", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when a scheduled change request is suspended 1`] = ` { - "text": "Change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* in the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* was suspended for the following reason: The user who scheduled this change request (user id: 6) has been deleted from this Unleash instance.", + "label": "Change request suspended", + "text": "Change request **[#1](unleashUrl/projects/my-other-project/change-requests/1)** in the **production** environment in project **[my-other-project](unleashUrl/projects/my-other-project)** was suspended for the following reason: The user who scheduled this change request (user id: 6) has been deleted from this Unleash instance.", "url": "unleashUrl/projects/my-other-project/change-requests/1", } `; exports[`Should format specialised text for events when change request is scheduled 1`] = ` { - "text": "*user@company.com* scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature flag *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* to be applied at in project *my-other-project*", + "label": "Change request scheduled", + "text": "**user@company.com** scheduled change request **[#1](unleashUrl/projects/my-other-project/change-requests/1)** for feature flag **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in the **production** environment in project **[my-other-project](unleashUrl/projects/my-other-project)** to be applied at in project **my-other-project**", "url": "unleashUrl/projects/my-other-project/change-requests/1", } `; exports[`Should format specialised text for events when constraints and rollout percentage and stickiness changed 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *flexibleRollout* in *production* stickiness from default to random; rollout from 67% to 32%; constraints from empty set of constraints to [appName is one of (x,y)]", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **flexibleRollout** in **production** stickiness from default to random; rollout from 67% to 32%; constraints from empty set of constraints to [appName is one of (x,y)]", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when default strategy updated 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from empty set of constraints to [appName is one of (x,y), appName not is one of (x)]", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from empty set of constraints to [appName is one of (x,y), appName not is one of (x)]", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated 2`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from empty set of constraints to [appName is not one of (x,y), appName not is not one of (x)]", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from empty set of constraints to [appName is not one of (x,y), appName not is not one of (x)]", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated 3`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from empty set of constraints to [appName is a string that contains (x,y), appName not is a string that contains (x)]", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from empty set of constraints to [appName is a string that contains (x,y), appName not is a string that contains (x)]", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated 4`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from empty set of constraints to [appName is a string that starts with (x,y), appName not is a string that starts with (x)]", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from empty set of constraints to [appName is a string that starts with (x,y), appName not is a string that starts with (x)]", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated 5`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from empty set of constraints to [appName is a string that ends with (x,y), appName not is a string that ends with (x)]", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from empty set of constraints to [appName is a string that ends with (x,y), appName not is a string that ends with (x)]", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint DATE_AFTER 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a date after 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a date after 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint DATE_BEFORE 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a date before 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a date before 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint NUM_EQ 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a number equal to 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a number equal to 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint NUM_GT 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a number greater than 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a number greater than 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint NUM_GTE 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a number greater than or equal to 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a number greater than or equal to 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint NUM_LT 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a number less than 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a number less than 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint NUM_LTE 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a number less than or equal to 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a number less than or equal to 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint SEMVER_EQ 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a SemVer equal to 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a SemVer equal to 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint SEMVER_GT 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a SemVer greater than 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a SemVer greater than 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when default strategy updated with numeric constraint SEMVER_LT 1`] = ` { - "text": "*admin* updated *[aaa](unleashUrl/projects/default/features/aaa)* in project *[default](unleashUrl/projects/default)* by updating strategy *default* in *production* constraints from [appName is a SemVer less than 4] to empty set of constraints", + "label": "Flag strategy updated", + "text": "**admin** updated **[aaa](unleashUrl/projects/default/features/aaa)** in project **[default](unleashUrl/projects/default)** by updating strategy **default** in **production** constraints from [appName is a SemVer less than 4] to empty set of constraints", "url": "unleashUrl/projects/default/features/aaa", } `; exports[`Should format specialised text for events when groupId changed 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *flexibleRollout* in *production* groupId from new-feature to different-feature", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **flexibleRollout** in **production** groupId from new-feature to different-feature", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when host names changed 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *applicationHostname* in *production* hostNames from empty set of hostNames to [unleash.com]; constraints from empty set of constraints to [appName is one of (x,y)]", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **applicationHostname** in **production** hostNames from empty set of hostNames to [unleash.com]; constraints from empty set of constraints to [appName is one of (x,y)]", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when neither rollout percentage nor stickiness changed 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *flexibleRollout* in *production*", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **flexibleRollout** in **production**", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when no specific text for strategy exists yet 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *newStrategy* in *production*", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **newStrategy** in **production**", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when rollout percentage changed 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *flexibleRollout* in *production* rollout from 67% to 32%", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **flexibleRollout** in **production** rollout from 67% to 32%", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when scheduled change request fails 1`] = ` { - "text": "*Failed* to apply the scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature flag *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* by *user@company.com* in project *my-other-project*.", + "label": "Scheduled change request failed", + "text": "**Failed** to apply the scheduled change request **[#1](unleashUrl/projects/my-other-project/change-requests/1)** for feature flag **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in the **production** environment in project **[my-other-project](unleashUrl/projects/my-other-project)** by **user@company.com** in project **my-other-project**.", "url": "unleashUrl/projects/my-other-project/change-requests/1", } `; exports[`Should format specialised text for events when scheduled change request succeeds 1`] = ` { - "text": "*Successfully* applied the scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature flag *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* by *user@company.com* in project *my-other-project*.", + "label": "Scheduled change request applied successfully", + "text": "**Successfully** applied the scheduled change request **[#1](unleashUrl/projects/my-other-project/change-requests/1)** for feature flag **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in the **production** environment in project **[my-other-project](unleashUrl/projects/my-other-project)** by **user@company.com** in project **my-other-project**.", "url": "unleashUrl/projects/my-other-project/change-requests/1", } `; exports[`Should format specialised text for events when stickiness changed 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *flexibleRollout* in *production* stickiness from default to random", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **flexibleRollout** in **production** stickiness from default to random", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when strategy added 1`] = ` { - "text": "*user@company.com* added strategy *flexibleRollout* to *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* for the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)*", + "label": "Flag strategy added", + "text": "**user@company.com** added strategy **flexibleRollout** to **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** for the **production** environment in project **[my-other-project](unleashUrl/projects/my-other-project)**", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when strategy removed 1`] = ` { - "text": "*user@company.com* removed strategy *default* from *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* for the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)*", + "label": "Flag strategy removed", + "text": "**user@company.com** removed strategy **default** from **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** for the **production** environment in project **[my-other-project](unleashUrl/projects/my-other-project)**", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; exports[`Should format specialised text for events when userIds changed 1`] = ` { - "text": "*user@company.com* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *userWithId* in *production* userIds from empty set of userIds to [a,b]; constraints from empty set of constraints to [appName is one of (x,y)]", + "label": "Flag strategy updated", + "text": "**user@company.com** updated **[new-feature](unleashUrl/projects/my-other-project/features/new-feature)** in project **[my-other-project](unleashUrl/projects/my-other-project)** by updating strategy **userWithId** in **production** userIds from empty set of userIds to [a,b]; constraints from empty set of constraints to [appName is one of (x,y)]", "url": "unleashUrl/projects/my-other-project/features/new-feature", } `; diff --git a/src/lib/addons/__snapshots__/slack.test.ts.snap b/src/lib/addons/__snapshots__/slack.test.ts.snap index 5a38efeaa1..e30b99792a 100644 --- a/src/lib/addons/__snapshots__/slack.test.ts.snap +++ b/src/lib/addons/__snapshots__/slack.test.ts.snap @@ -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":"*some@user.com* created ** in project **","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":"**some@user.com** created **** in project ****","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":"*some@user.com* 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":"**some@user.com** 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":"*some@user.com* 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/some-project/archive"}]}]}"`; +exports[`Slack integration Should call slack webhook for archived toggle with project info 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"**some@user.com** 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/some-project/archive"}]}]}"`; -exports[`Slack integration Should call webhook for toggled environment 1`] = `"{"username":"Unleash","icon_emoji":":unleash:","text":"*some@user.com* disabled ** for the *development* environment in project **","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":"**some@user.com** disabled **** for the **development** environment in project ****","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":"*some@user.com* disabled ** for the *development* environment in project **","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":"**some@user.com** disabled **** for the **development** environment in project ****","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`] = ` { diff --git a/src/lib/addons/__snapshots__/teams.test.ts.snap b/src/lib/addons/__snapshots__/teams.test.ts.snap index fe2875686a..042fc10b98 100644 --- a/src/lib/addons/__snapshots__/teams.test.ts.snap +++ b/src/lib/addons/__snapshots__/teams.test.ts.snap @@ -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":"*some@user.com* created *[some-toggle](http://some-url.com/projects//features/some-toggle)* in project **","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"some@user.com"},{"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":"**some@user.com** created **[some-toggle](http://some-url.com/projects//features/some-toggle)** in project ****","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"some@user.com"},{"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":"*some@user.com* archived *some-toggle* in project **","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"some@user.com"},{"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":"**some@user.com** archived **some-toggle** in project ****","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"some@user.com"},{"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":"*some@user.com* archived *some-toggle* in project *[some-project](http://some-url.com/projects/some-project)*","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"some@user.com"},{"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":"**some@user.com** archived **some-toggle** in project **[some-project](http://some-url.com/projects/some-project)**","activitySubtitle":"Unleash notification update","facts":[{"name":"User","value":"some@user.com"},{"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":"*some@user.com* 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":"some@user.com"},{"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":"**some@user.com** 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":"some@user.com"},{"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":"*some@user.com* 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":"some@user.com"},{"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":"**some@user.com** 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":"some@user.com"},{"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`] = ` { diff --git a/src/lib/addons/__snapshots__/webhook.test.ts.snap b/src/lib/addons/__snapshots__/webhook.test.ts.snap index 59d357fd93..584ee428f7 100644 --- a/src/lib/addons/__snapshots__/webhook.test.ts.snap +++ b/src/lib/addons/__snapshots__/webhook.test.ts.snap @@ -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": "*some@user.com* created *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* in project *[default](http://some-url.com/projects/default)*" + "markdown": "**some@user.com** created **[some-toggle](http://some-url.com/projects/default/features/some-toggle)** in project **[default](http://some-url.com/projects/default)**" }" `; diff --git a/src/lib/addons/feature-event-formatter-md.ts b/src/lib/addons/feature-event-formatter-md.ts index 5613b028f7..209c3655d9 100644 --- a/src/lib/addons/feature-event-formatter-md.ts +++ b/src/lib/addons/feature-event-formatter-md.ts @@ -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 = { [ADDON_CONFIG_CREATED]: { diff --git a/src/lib/addons/slack-app.test.ts b/src/lib/addons/slack-app.test.ts index cac4d98dd8..056c364214 100644 --- a/src/lib/addons/slack-app.test.ts +++ b/src/lib/addons/slack-app.test.ts @@ -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[] = []; @@ -271,8 +272,7 @@ describe('SlackAppAddon', () => { event: serializeDates(eventWith2Tags), details: { channels: ['general', 'another-channel-1', 'another-channel-2'], - message: - '*some@user.com* enabled ** for the *development* environment in project **', + message: `${bold('some@user.com')} enabled ${bold('')} for the ${bold('development')} environment in project ${bold('')}`, }, }); }); diff --git a/src/lib/addons/slack.test.ts b/src/lib/addons/slack.test.ts index eba87005c7..2e66ff755c 100644 --- a/src/lib/addons/slack.test.ts +++ b/src/lib/addons/slack.test.ts @@ -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(); @@ -338,8 +339,7 @@ describe('Slack integration', () => { url: parameters.url, channels: ['general'], username: 'Unleash', - message: - '*some@user.com* disabled ** for the *development* environment in project **', + message: `${bold('some@user.com')} disabled ${bold('')} for the ${bold('development')} environment in project ${bold('')}`, }, }); }); diff --git a/src/lib/addons/teams.test.ts b/src/lib/addons/teams.test.ts index 8c1b14c0bb..f15bf1a63d 100644 --- a/src/lib/addons/teams.test.ts +++ b/src/lib/addons/teams.test.ts @@ -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(); @@ -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: [ {