0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/config/presets/http/index.spec.ts
2024-02-24 07:16:34 +00:00

51 lines
1.5 KiB
TypeScript

import * as httpMock from '../../../../test/http-mock';
import { PRESET_DEP_NOT_FOUND, PRESET_INVALID_JSON } from '../util';
import * as http from '.';
const host = 'https://my.server/';
const filePath = '/test-preset.json';
const repo = 'https://my.server/test-preset.json';
describe('config/presets/http/index', () => {
describe('getPreset()', () => {
it('should return parsed JSON', async () => {
httpMock.scope(host).get(filePath).reply(200, { foo: 'bar' });
expect(await http.getPreset({ repo })).toEqual({ foo: 'bar' });
});
it('should return parsed JSON5', async () => {
httpMock
.scope('https://my.server/')
.get('/test-preset.json5')
.reply(200, '{ foo: "bar" } // comment');
const repo = 'https://my.server/test-preset.json5';
expect(await http.getPreset({ repo })).toEqual({ foo: 'bar' });
});
it('throws if fails to parse', async () => {
httpMock.scope(host).get(filePath).reply(200, 'not json');
await expect(http.getPreset({ repo })).rejects.toThrow(
PRESET_INVALID_JSON,
);
});
it('throws if file not found', async () => {
httpMock.scope(host).get(filePath).reply(404);
await expect(http.getPreset({ repo })).rejects.toThrow(
PRESET_DEP_NOT_FOUND,
);
});
it('throws on malformed URL', async () => {
await expect(http.getPreset({ repo: 'malformed!' })).rejects.toThrow(
PRESET_DEP_NOT_FOUND,
);
});
});
});