mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-13 03:35:52 +01:00
66f4197236
* chore: test * chore: add * chore: more progress * chore: progress in migration, fix prettier parser * chore: reduce tsc errors * chore: refactor storage utils types * chore: refactor utils types * chore: refactor local storage types * chore: refactor config utils types * chore: refactor tsc types * refactor: apply eslint fix, tabs etc * chore: fix lint errors * test: update unit test conf to typescript setup few test refactored to typescript * chore: enable more unit test migrate to typescript * chore: migrate storage test to tsc * chore: migrate up storage test to tsc * refactor: enable plugin and auth test * chore: migrate plugin loader test * chore: update dependencies * chore: migrate functional test to typescript * chore: add codecove * chore: update express * chore: downgrade puppeteer The latest version does not seems to work properly fine. * chore: update dependencies
86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
import {parseConfigurationFile} from '../../__helper';
|
|
import {parseConfigFile} from '../../../../src/lib/utils';
|
|
import {notify} from '../../../../src/lib/notify';
|
|
|
|
import {notifyRequest} from '../../../../src/lib/notify/notify-request';
|
|
|
|
import { setup } from '../../../../src/lib/logger';
|
|
|
|
setup([]);
|
|
|
|
jest.mock('./../../../../src/lib/notify/notify-request', () => ({
|
|
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'));
|
|
|
|
describe('Notifications:: 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 () => {
|
|
// @ts-ignore
|
|
await notify({}, {});
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(0);
|
|
});
|
|
|
|
test("should send notification", async () => {
|
|
const name = 'package';
|
|
// @ts-ignore
|
|
const response = await notify({name}, singleNotificationConfig, { name: 'foo'}, 'bar');
|
|
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 () => {
|
|
// @ts-ignore
|
|
await notify({}, singleHeaderNotificationConfig, { name: 'foo'}, 'bar');
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
test("should send multiple notification", async () => {
|
|
// @ts-ignore
|
|
await notify({name}, multiNotificationConfig, { name: 'foo'}, 'bar');
|
|
|
|
expect(notifyRequest).toHaveBeenCalled();
|
|
expect(notifyRequest).toHaveBeenCalledTimes(3);
|
|
});
|
|
|
|
describe('packagePatternFlags', () => {
|
|
test("should send single notification with packagePatternFlags", async () => {
|
|
const name = 'package';
|
|
await notify({name}, packagePatternNotificationConfig, { name: 'foo'}, 'bar');
|
|
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
test("should not match on send single notification with packagePatternFlags", async () => {
|
|
const name = 'no-mach-name';
|
|
await notify({name}, packagePatternNotificationConfig, { name: 'foo'}, 'bar');
|
|
|
|
expect(notifyRequest).toHaveBeenCalledTimes(0);
|
|
});
|
|
})
|
|
|
|
|
|
});
|