2021-04-29 10:21:29 +02:00
|
|
|
const { FEATURE_CREATED, FEATURE_ARCHIVED } = require('../types/events');
|
2021-04-28 12:38:11 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
jest.mock(
|
|
|
|
'./addon',
|
|
|
|
() =>
|
|
|
|
class Addon {
|
|
|
|
constructor(definition, { getLogger }) {
|
|
|
|
this.logger = getLogger('addon/test');
|
|
|
|
this.fetchRetryCalls = [];
|
|
|
|
}
|
2021-04-28 12:38:11 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
async fetchRetry(url, options, retries, backoff) {
|
|
|
|
this.fetchRetryCalls.push({ url, options, retries, backoff });
|
|
|
|
return Promise.resolve({ status: 200 });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
const TeamsAddon = require('./teams');
|
2021-04-28 12:38:11 +02:00
|
|
|
|
|
|
|
const noLogger = require('../../test/fixtures/no-logger');
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Should call teams webhook', async () => {
|
2021-04-28 12:38:11 +02:00
|
|
|
const addon = new TeamsAddon({
|
|
|
|
getLogger: noLogger,
|
|
|
|
unleashUrl: 'http://some-url.com',
|
|
|
|
});
|
|
|
|
const event = {
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.office.com',
|
|
|
|
};
|
|
|
|
|
|
|
|
await addon.handleEvent(event, parameters);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(addon.fetchRetryCalls.length).toBe(1);
|
|
|
|
expect(addon.fetchRetryCalls[0].url).toBe(parameters.url);
|
|
|
|
expect(addon.fetchRetryCalls[0].options.body).toMatchSnapshot();
|
2021-04-28 12:38:11 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Should call teams webhook for archived toggle', async () => {
|
2021-04-28 12:38:11 +02:00
|
|
|
const addon = new TeamsAddon({
|
|
|
|
getLogger: noLogger,
|
|
|
|
unleashUrl: 'http://some-url.com',
|
|
|
|
});
|
|
|
|
const event = {
|
|
|
|
type: FEATURE_ARCHIVED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
url: 'http://hooks.office.com',
|
|
|
|
};
|
|
|
|
|
|
|
|
await addon.handleEvent(event, parameters);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(addon.fetchRetryCalls.length).toBe(1);
|
|
|
|
expect(addon.fetchRetryCalls[0].url).toBe(parameters.url);
|
|
|
|
expect(addon.fetchRetryCalls[0].options.body).toMatchSnapshot();
|
2021-04-28 12:38:11 +02:00
|
|
|
});
|