2021-03-14 02:42:46 -05:00
|
|
|
import { parseConfigurationFile } from '../../__helper';
|
|
|
|
import { parseConfigFile } from '../../../../src/lib/utils';
|
|
|
|
import { notify } from '../../../../src/lib/notify';
|
2018-09-22 05:54:21 -05:00
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
import { notifyRequest } from '../../../../src/lib/notify/notify-request';
|
2018-09-22 05:54:21 -05:00
|
|
|
|
2019-07-16 01:40:01 -05:00
|
|
|
import { setup } from '../../../../src/lib/logger';
|
|
|
|
|
|
|
|
setup([]);
|
|
|
|
|
2019-05-20 00:33:39 -05:00
|
|
|
jest.mock('./../../../../src/lib/notify/notify-request', () => ({
|
2018-09-22 05:54:21 -05:00
|
|
|
notifyRequest: jest.fn((options, content) => Promise.resolve([options, content]))
|
|
|
|
}));
|
|
|
|
|
|
|
|
const parseConfigurationNotifyFile = (name) => {
|
|
|
|
return parseConfigurationFile(`notify/${name}`);
|
|
|
|
};
|
|
|
|
const singleNotificationConfig = parseConfigFile(parseConfigurationNotifyFile('single.notify'));
|
2021-03-14 02:42:46 -05:00
|
|
|
const singleHeaderNotificationConfig = parseConfigFile(
|
|
|
|
parseConfigurationNotifyFile('single.header.notify')
|
|
|
|
);
|
|
|
|
const packagePatternNotificationConfig = parseConfigFile(
|
|
|
|
parseConfigurationNotifyFile('single.packagePattern.notify')
|
|
|
|
);
|
2018-09-22 05:54:21 -05:00
|
|
|
const multiNotificationConfig = parseConfigFile(parseConfigurationNotifyFile('multiple.notify'));
|
|
|
|
|
2019-05-20 00:33:39 -05:00
|
|
|
describe('Notifications:: Notify', () => {
|
2018-09-22 05:54:21 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2019-12-23 03:29:27 -05:00
|
|
|
// FUTURE: we should add some sort of health check of all props, (not implemented yet)
|
2018-09-22 05:54:21 -05:00
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
test('should not fails if config is not provided', async () => {
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2018-09-22 05:54:21 -05:00
|
|
|
await notify({}, {});
|
|
|
|
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(0);
|
|
|
|
});
|
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
test('should send notification', async () => {
|
2019-07-16 01:40:01 -05:00
|
|
|
const name = 'package';
|
|
|
|
// @ts-ignore
|
2021-03-14 02:42:46 -05:00
|
|
|
const response = await notify({ name }, singleNotificationConfig, { name: 'foo' }, 'bar');
|
2018-09-22 05:54:21 -05:00
|
|
|
const [options, content] = response;
|
|
|
|
|
|
|
|
expect(options.headers).toBeDefined();
|
|
|
|
expect(options.url).toBeDefined();
|
|
|
|
expect(options.body).toBeDefined();
|
|
|
|
expect(content).toMatch(name);
|
|
|
|
expect(response).toBeTruthy();
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
test('should send single header notification', async () => {
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2021-03-14 02:42:46 -05:00
|
|
|
await notify({}, singleHeaderNotificationConfig, { name: 'foo' }, 'bar');
|
2018-09-22 05:54:21 -05:00
|
|
|
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
test('should send multiple notification', async () => {
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2021-03-14 02:42:46 -05:00
|
|
|
await notify({ name }, multiNotificationConfig, { name: 'foo' }, 'bar');
|
2018-09-22 05:54:21 -05:00
|
|
|
|
2019-07-16 01:40:01 -05:00
|
|
|
expect(notifyRequest).toHaveBeenCalled();
|
2018-09-22 05:54:21 -05:00
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('packagePatternFlags', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
test('should send single notification with packagePatternFlags', async () => {
|
2019-07-16 01:40:01 -05:00
|
|
|
const name = 'package';
|
2019-08-16 14:20:18 -05:00
|
|
|
// @ts-ignore
|
2021-03-14 02:42:46 -05:00
|
|
|
await notify({ name }, packagePatternNotificationConfig, { name: 'foo' }, 'bar');
|
2018-09-22 05:54:21 -05:00
|
|
|
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
test('should not match on send single notification with packagePatternFlags', async () => {
|
2019-07-16 01:40:01 -05:00
|
|
|
const name = 'no-mach-name';
|
2019-08-16 14:20:18 -05:00
|
|
|
// @ts-ignore
|
2021-03-14 02:42:46 -05:00
|
|
|
await notify({ name }, packagePatternNotificationConfig, { name: 'foo' }, 'bar');
|
2018-09-22 05:54:21 -05:00
|
|
|
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(0);
|
|
|
|
});
|
2021-03-14 02:42:46 -05:00
|
|
|
});
|
2018-09-22 05:54:21 -05:00
|
|
|
});
|