2021-10-07 10:22:20 +02:00
|
|
|
import {
|
|
|
|
FEATURE_CREATED,
|
|
|
|
FEATURE_ARCHIVED,
|
|
|
|
FEATURE_ENVIRONMENT_DISABLED,
|
2024-03-18 13:58:05 +01:00
|
|
|
type IEvent,
|
2021-10-07 10:22:20 +02:00
|
|
|
} from '../types/events';
|
2024-03-18 13:58:05 +01:00
|
|
|
import type { Logger } from '../logger';
|
2021-08-12 15:04:37 +02:00
|
|
|
|
|
|
|
import SlackAddon from './slack';
|
|
|
|
|
|
|
|
import noLogger from '../../test/fixtures/no-logger';
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
import {
|
|
|
|
type IAddonConfig,
|
|
|
|
type IFlagResolver,
|
|
|
|
SYSTEM_USER_ID,
|
|
|
|
} from '../types';
|
|
|
|
import type { IntegrationEventsService } from '../services';
|
2021-08-12 15:04:37 +02:00
|
|
|
|
|
|
|
let fetchRetryCalls: any[] = [];
|
2021-01-19 10:42:45 +01:00
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const INTEGRATION_ID = 1337;
|
|
|
|
const ARGS: IAddonConfig = {
|
|
|
|
getLogger: noLogger,
|
|
|
|
unleashUrl: 'http://some-url.com',
|
|
|
|
integrationEventsService: {} as IntegrationEventsService,
|
|
|
|
flagResolver: {} as IFlagResolver,
|
|
|
|
};
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
jest.mock(
|
|
|
|
'./addon',
|
|
|
|
() =>
|
|
|
|
class Addon {
|
2021-08-12 15:04:37 +02:00
|
|
|
logger: Logger;
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
constructor(definition, { getLogger }) {
|
|
|
|
this.logger = getLogger('addon/test');
|
2021-08-12 15:04:37 +02:00
|
|
|
fetchRetryCalls = [];
|
2021-05-28 11:10:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async fetchRetry(url, options, retries, backoff) {
|
2021-08-12 15:04:37 +02:00
|
|
|
fetchRetryCalls.push({
|
|
|
|
url,
|
|
|
|
options,
|
|
|
|
retries,
|
|
|
|
backoff,
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
return Promise.resolve({ status: 200 });
|
|
|
|
}
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
|
|
|
|
async registerEvent(_) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
2021-05-28 11:10:24 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
test('Should call slack webhook', async () => {
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const addon = new SlackAddon(ARGS);
|
2021-08-12 15:04:37 +02:00
|
|
|
const event: IEvent = {
|
|
|
|
id: 1,
|
|
|
|
createdAt: new Date(),
|
2021-01-19 10:42:45 +01:00
|
|
|
type: FEATURE_CREATED,
|
2023-12-14 13:45:25 +01:00
|
|
|
createdByUserId: SYSTEM_USER_ID,
|
2021-01-19 10:42:45 +01:00
|
|
|
createdBy: 'some@user.com',
|
2021-10-28 14:09:11 +02:00
|
|
|
project: 'default',
|
2021-11-12 13:15:51 +01:00
|
|
|
featureName: 'some-toggle',
|
2021-01-19 10:42:45 +01:00
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
2021-10-28 14:09:11 +02:00
|
|
|
type: 'release',
|
2021-01-19 10:42:45 +01:00
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.slack.com',
|
2023-07-05 09:42:17 +02:00
|
|
|
defaultChannel: 'general',
|
2021-01-19 10:42:45 +01:00
|
|
|
};
|
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
2021-08-12 15:04:37 +02:00
|
|
|
expect(fetchRetryCalls.length).toBe(1);
|
|
|
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
|
|
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Should call slack webhook for archived toggle', async () => {
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const addon = new SlackAddon(ARGS);
|
2021-08-12 15:04:37 +02:00
|
|
|
const event: IEvent = {
|
|
|
|
id: 2,
|
|
|
|
createdAt: new Date(),
|
2023-12-14 13:45:25 +01:00
|
|
|
createdByUserId: SYSTEM_USER_ID,
|
2021-03-05 12:59:35 +01:00
|
|
|
type: FEATURE_ARCHIVED,
|
2021-11-12 13:15:51 +01:00
|
|
|
featureName: 'some-toggle',
|
2022-10-05 11:30:51 +02:00
|
|
|
createdBy: 'some@user.com',
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.slack.com',
|
2023-07-05 09:42:17 +02:00
|
|
|
defaultChannel: 'general',
|
2022-10-05 11:30:51 +02:00
|
|
|
};
|
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
2022-10-05 11:30:51 +02:00
|
|
|
expect(fetchRetryCalls.length).toBe(1);
|
|
|
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
|
|
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Should call slack webhook for archived toggle with project info', async () => {
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const addon = new SlackAddon(ARGS);
|
2022-10-05 11:30:51 +02:00
|
|
|
const event: IEvent = {
|
|
|
|
id: 2,
|
|
|
|
createdAt: new Date(),
|
2023-12-14 13:45:25 +01:00
|
|
|
createdByUserId: SYSTEM_USER_ID,
|
2022-10-05 11:30:51 +02:00
|
|
|
type: FEATURE_ARCHIVED,
|
|
|
|
featureName: 'some-toggle',
|
|
|
|
project: 'some-project',
|
2021-03-05 12:59:35 +01:00
|
|
|
createdBy: 'some@user.com',
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.slack.com',
|
2023-07-05 09:42:17 +02:00
|
|
|
defaultChannel: 'general',
|
2021-03-05 12:59:35 +01:00
|
|
|
};
|
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
2021-08-12 15:04:37 +02:00
|
|
|
expect(fetchRetryCalls.length).toBe(1);
|
|
|
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
|
|
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
2021-03-05 12:59:35 +01:00
|
|
|
});
|
|
|
|
|
2021-10-07 10:22:20 +02:00
|
|
|
test(`Should call webhook for toggled environment`, async () => {
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const addon = new SlackAddon(ARGS);
|
2021-10-07 10:22:20 +02:00
|
|
|
const event: IEvent = {
|
|
|
|
id: 2,
|
|
|
|
createdAt: new Date(),
|
2023-12-14 13:45:25 +01:00
|
|
|
createdByUserId: SYSTEM_USER_ID,
|
2021-10-07 10:22:20 +02:00
|
|
|
type: FEATURE_ENVIRONMENT_DISABLED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
environment: 'development',
|
|
|
|
project: 'default',
|
2021-11-12 13:15:51 +01:00
|
|
|
featureName: 'some-toggle',
|
2021-10-07 10:22:20 +02:00
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.slack.com',
|
2023-07-05 09:42:17 +02:00
|
|
|
defaultChannel: 'general',
|
2021-10-07 10:22:20 +02:00
|
|
|
};
|
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
2021-10-07 10:22:20 +02:00
|
|
|
expect(fetchRetryCalls).toHaveLength(1);
|
|
|
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
|
|
|
expect(fetchRetryCalls[0].options.body).toMatch(/disabled/);
|
|
|
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Should use default channel', async () => {
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const addon = new SlackAddon(ARGS);
|
2021-08-12 15:04:37 +02:00
|
|
|
const event: IEvent = {
|
|
|
|
id: 3,
|
|
|
|
createdAt: new Date(),
|
2023-12-14 13:45:25 +01:00
|
|
|
createdByUserId: SYSTEM_USER_ID,
|
2021-01-19 10:42:45 +01:00
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
2021-11-12 13:15:51 +01:00
|
|
|
featureName: 'some-toggle',
|
2021-01-19 10:42:45 +01:00
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.slack.com',
|
|
|
|
defaultChannel: 'some-channel',
|
|
|
|
};
|
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const req = JSON.parse(fetchRetryCalls[0].options.body);
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(req.channel).toBe('#some-channel');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Should override default channel with data from tag', async () => {
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const addon = new SlackAddon(ARGS);
|
2021-08-12 15:04:37 +02:00
|
|
|
const event: IEvent = {
|
|
|
|
id: 4,
|
|
|
|
createdAt: new Date(),
|
2023-12-14 13:45:25 +01:00
|
|
|
createdByUserId: SYSTEM_USER_ID,
|
2021-01-19 10:42:45 +01:00
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
2021-11-12 13:15:51 +01:00
|
|
|
featureName: 'some-toggle',
|
2021-01-19 10:42:45 +01:00
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
tags: [
|
|
|
|
{
|
|
|
|
type: 'slack',
|
|
|
|
value: 'another-channel',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.slack.com',
|
|
|
|
defaultChannel: 'some-channel',
|
|
|
|
};
|
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const req = JSON.parse(fetchRetryCalls[0].options.body);
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(req.channel).toBe('#another-channel');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Should post to all channels in tags', async () => {
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const addon = new SlackAddon(ARGS);
|
2021-08-12 15:04:37 +02:00
|
|
|
const event: IEvent = {
|
|
|
|
id: 5,
|
|
|
|
createdAt: new Date(),
|
2023-12-14 13:45:25 +01:00
|
|
|
createdByUserId: SYSTEM_USER_ID,
|
2021-01-19 10:42:45 +01:00
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
2021-11-12 13:15:51 +01:00
|
|
|
featureName: 'some-toggle',
|
2021-01-19 10:42:45 +01:00
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
tags: [
|
|
|
|
{
|
|
|
|
type: 'slack',
|
|
|
|
value: 'another-channel-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'slack',
|
|
|
|
value: 'another-channel-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.slack.com',
|
|
|
|
defaultChannel: 'some-channel',
|
|
|
|
};
|
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const req1 = JSON.parse(fetchRetryCalls[0].options.body);
|
|
|
|
const req2 = JSON.parse(fetchRetryCalls[1].options.body);
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
expect(fetchRetryCalls).toHaveLength(2);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(req1.channel).toBe('#another-channel-1');
|
|
|
|
expect(req2.channel).toBe('#another-channel-2');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
2023-07-05 09:42:17 +02:00
|
|
|
|
|
|
|
test('Should include custom headers from parameters in call to service', async () => {
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
const addon = new SlackAddon(ARGS);
|
2023-07-05 09:42:17 +02:00
|
|
|
const event: IEvent = {
|
|
|
|
id: 2,
|
|
|
|
createdAt: new Date(),
|
|
|
|
type: FEATURE_ENVIRONMENT_DISABLED,
|
2023-12-14 13:45:25 +01:00
|
|
|
createdByUserId: SYSTEM_USER_ID,
|
2023-07-05 09:42:17 +02:00
|
|
|
createdBy: 'some@user.com',
|
|
|
|
environment: 'development',
|
|
|
|
project: 'default',
|
|
|
|
featureName: 'some-toggle',
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.slack.com',
|
|
|
|
defaultChannel: 'general',
|
|
|
|
customHeaders: `{ "MY_CUSTOM_HEADER": "MY_CUSTOM_VALUE" }`,
|
|
|
|
};
|
|
|
|
|
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook
Registers integration events in the **Webhook** integration.
Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.
Here's an example of how this looks like in the database table:
```json
{
"id": 7,
"integration_id": 2,
"created_at": "2024-07-18T18:11:11.376348+01:00",
"state": "failed",
"state_details": "Webhook request failed with status code: ECONNREFUSED",
"event": {
"id": 130,
"data": null,
"tags": [],
"type": "feature-environment-enabled",
"preData": null,
"project": "default",
"createdAt": "2024-07-18T17:11:10.821Z",
"createdBy": "admin",
"environment": "development",
"featureName": "test",
"createdByUserId": 1
},
"details": {
"url": "http://localhost:1337",
"body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
}
}
```
2024-07-19 11:07:52 +02:00
|
|
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
2023-07-05 09:42:17 +02:00
|
|
|
expect(fetchRetryCalls).toHaveLength(1);
|
|
|
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
|
|
|
expect(fetchRetryCalls[0].options.body).toMatch(/disabled/);
|
|
|
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
|
|
|
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
|
|
|
|
});
|