2018-09-12 10:16:17 +00:00
|
|
|
const { update, find, clear } = require('../../lib/util/host-rules');
|
2018-07-06 05:26:36 +00:00
|
|
|
|
2018-09-12 10:16:17 +00:00
|
|
|
describe('util/host-rules', () => {
|
2018-07-06 05:26:36 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
clear();
|
|
|
|
});
|
|
|
|
describe('update()', () => {
|
|
|
|
it('throws if no platform ', () => {
|
|
|
|
expect(() => update({})).toThrow(
|
2018-10-15 11:37:08 +00:00
|
|
|
'Failed to set configuration: no platform or endpoint specified'
|
2018-07-06 05:26:36 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('throws if no endpoint ', () => {
|
2019-01-14 14:22:24 +00:00
|
|
|
expect(() => update({ platform: 'azure' })).toThrow(
|
|
|
|
`Failed to configure platform 'azure': no endpoint defined`
|
2018-07-06 05:26:36 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws if invalid endpoint ', () => {
|
|
|
|
expect(() =>
|
2019-01-14 14:22:24 +00:00
|
|
|
update({ platform: 'azure', endpoint: '/some/path' })
|
2018-07-06 05:26:36 +00:00
|
|
|
).toThrow(
|
2019-01-14 14:22:24 +00:00
|
|
|
`Failed to configure platform 'azure': no host for endpoint '/some/path'`
|
2018-07-06 05:26:36 +00:00
|
|
|
);
|
|
|
|
});
|
2018-10-15 11:37:08 +00:00
|
|
|
it('supports endpoint-only', () => {
|
|
|
|
update({
|
|
|
|
endpoint: 'https://some.endpoint',
|
|
|
|
username: 'user1',
|
|
|
|
password: 'pass1',
|
|
|
|
});
|
|
|
|
expect(find({ host: 'some.endpoint' })).toMatchSnapshot();
|
|
|
|
});
|
2018-07-06 05:26:36 +00:00
|
|
|
it('uses default endpoint', () => {
|
|
|
|
update({
|
|
|
|
platform: 'github',
|
|
|
|
token: 'token',
|
|
|
|
other: 'data',
|
|
|
|
});
|
|
|
|
expect(find({ platform: 'github' })).toMatchSnapshot();
|
|
|
|
expect(
|
|
|
|
find({ platform: 'github', host: 'api.github.com' })
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(find({ platform: 'github', host: 'example.com' })).toBe(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('find()', () => {
|
|
|
|
it('allows overrides', () => {
|
|
|
|
update({
|
|
|
|
platform: 'github',
|
|
|
|
endpoint: 'endpoint',
|
|
|
|
token: 'token',
|
|
|
|
other: 'data',
|
|
|
|
});
|
|
|
|
const overrides = {
|
|
|
|
token: 'secret',
|
|
|
|
other: null,
|
|
|
|
foo: undefined,
|
|
|
|
};
|
|
|
|
expect(find({ platform: 'github' }, overrides)).toMatchSnapshot();
|
|
|
|
expect(
|
|
|
|
find({ platform: 'github', host: 'api.github.com' }, overrides)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(
|
|
|
|
find({ platform: 'github', host: 'example.com' }, overrides)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|