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