0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/test/unit/api/notify.spec.js
Juan Picado @jotadeveloper cf31982127
test: Increase coverage for unit test (#974)
* test(utils): add test for validate names

* test(utils): add unit test for dist-tags normalize utility

* refactor(notifications):  unit test for notifications

* test(cli): add unit test for address validation

* chore: add new constants

* chore: ignore debug from coverage

* test(bootstrap): test https is fails on start

* refactor: update code for rebase
2018-09-22 12:54:21 +02:00

81 lines
2.6 KiB
JavaScript

// @flow
import {parseConfigurationFile} from '../__helper';
import {parseConfigFile} from '../../../src/lib/utils';
import {notify} from '../../../src/lib/notify';
import {notifyRequest} from '../../../src/lib/notify/notify-request';
jest.mock('./../../../src/lib/notify/notify-request', () => ({
notifyRequest: jest.fn((options, content) => Promise.resolve([options, content]))
}));
require('../../../src/lib/logger').setup([]);
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'));
describe('Notify', () => {
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 () => {
await notify({}, {});
expect(notifyRequest).toHaveBeenCalledTimes(0);
});
test("should send notification", async () => {
const name: string = 'package';
const response = await notify({name}, singleNotificationConfig);
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 () => {
await notify({}, singleHeaderNotificationConfig);
expect(notifyRequest).toHaveBeenCalledTimes(1);
});
test("should send multiple notification", async () => {
await notify({}, multiNotificationConfig);
expect(notifyRequest).toHaveBeenCalledTimes(3);
});
describe('packagePatternFlags', () => {
test("should send single notification with packagePatternFlags", async () => {
const name: string = 'package';
await notify({name}, packagePatternNotificationConfig);
expect(notifyRequest).toHaveBeenCalledTimes(1);
});
test("should not match on send single notification with packagePatternFlags", async () => {
const name: string = 'no-mach-name';
await notify({name}, packagePatternNotificationConfig);
expect(notifyRequest).toHaveBeenCalledTimes(0);
});
})
});