diff --git a/lib/config/presets/__snapshots__/github.spec.ts.snap b/lib/config/presets/__snapshots__/github.spec.ts.snap new file mode 100644 index 0000000000000000000000000000000000000000..e1ce92515027c84d5475284f17acf758cab45a86 --- /dev/null +++ b/lib/config/presets/__snapshots__/github.spec.ts.snap @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`config/presets/github getPreset() uses default endpoint 1`] = ` +Array [ + Array [ + "https://api.github.com/repos/some/repo/contents/default.json", + Object { + "headers": Object { + "accept": "application/vnd.github.v3+json", + }, + "hooks": Object { + "beforeRedirect": Array [ + [Function], + ], + }, + "hostType": "github", + "json": true, + "method": "get", + }, + ], + Array [ + "https://api.github.com/repos/some/repo/contents/renovate.json", + Object { + "headers": Object { + "accept": "application/vnd.github.v3+json", + }, + "hooks": Object { + "beforeRedirect": Array [ + [Function], + ], + }, + "hostType": "github", + "json": true, + "method": "get", + }, + ], + Array [ + "https://api.github.com/repos/some/repo/contents/default.json", + Object { + "headers": Object { + "accept": "application/vnd.github.v3+json", + }, + "hooks": Object { + "beforeRedirect": Array [ + [Function], + ], + }, + "hostType": "github", + "json": true, + "method": "get", + }, + ], + Array [ + "https://api.github.com/repos/some/repo/contents/renovate.json", + Object { + "headers": Object { + "accept": "application/vnd.github.v3+json", + }, + "hooks": Object { + "beforeRedirect": Array [ + [Function], + ], + }, + "hostType": "github", + "json": true, + "method": "get", + }, + ], +] +`; diff --git a/lib/config/presets/__snapshots__/gitlab.spec.ts.snap b/lib/config/presets/__snapshots__/gitlab.spec.ts.snap new file mode 100644 index 0000000000000000000000000000000000000000..34e8c20b4f23752f2cdee1cf02bd73371a1e7f6c --- /dev/null +++ b/lib/config/presets/__snapshots__/gitlab.spec.ts.snap @@ -0,0 +1,12 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`config/presets/gitlab getPreset() uses default endpoint 1`] = ` +Array [ + Array [ + "https://gitlab.com/api/v4/projects/some%2Frepo/repository/branches", + ], + Array [ + "https://gitlab.com/api/v4/projects/some%2Frepo/repository/branches", + ], +] +`; diff --git a/lib/config/presets/github.spec.ts b/lib/config/presets/github.spec.ts index 04680ba5f019bd845bd3aa542306f234821025d7..16cc36ddf62d820b62d62558e5766ff4f6ce7899 100644 --- a/lib/config/presets/github.spec.ts +++ b/lib/config/presets/github.spec.ts @@ -1,14 +1,18 @@ +import { PartialDeep } from 'type-fest'; import * as github from './github'; import _got from '../../util/got'; import * as _hostRules from '../../util/host-rules'; import { PLATFORM_FAILURE } from '../../constants/error-messages'; +import { mocked } from '../../../test/util'; +import { GotResponse } from '../../platform'; +import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; jest.mock('../../platform/github/gh-got-wrapper'); jest.mock('../../util/got'); jest.mock('../../util/host-rules'); -const got: any = _got; -const hostRules: any = _hostRules; +const got: jest.Mock<PartialDeep<GotResponse>> = _got as never; +const hostRules = mocked(_hostRules); describe('config/presets/github', () => { beforeEach(() => { @@ -72,13 +76,20 @@ describe('config/presets/github', () => { it('uses default endpoint', async () => { await github.getPreset('some/repo', 'default').catch((_) => {}); + await github + .getPreset('some/repo', 'default', { + endpoint: 'https://api.github.example.org', + }) + .catch((_) => {}); expect(got.mock.calls[0][0]).toEqual( 'https://api.github.com/repos/some/repo/contents/default.json' ); + expect(got.mock.calls).toMatchSnapshot(); }); it('uses custom endpoint', async () => { await github .getPreset('some/repo', 'default', { + platform: PLATFORM_TYPE_GITHUB, endpoint: 'https://api.github.example.org', }) .catch((_) => {}); diff --git a/lib/config/presets/github.ts b/lib/config/presets/github.ts index 365294b7c858b85cff3b8d386d8c8742257c369e..8dc79fbb59707d7fe48ff76c09e98ec8f36f11e2 100644 --- a/lib/config/presets/github.ts +++ b/lib/config/presets/github.ts @@ -4,9 +4,9 @@ import { Http, HttpOptions } from '../../util/http'; import { PLATFORM_FAILURE } from '../../constants/error-messages'; import { ensureTrailingSlash } from '../../util/url'; import { RenovateConfig } from '../common'; +import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; -const id = 'github'; -const http = new Http(id); +const http = new Http(PLATFORM_TYPE_GITHUB); async function fetchJSONFile( repo: string, @@ -49,7 +49,9 @@ export async function getPreset( baseConfig?: RenovateConfig ): Promise<Preset> { const endpoint = ensureTrailingSlash( - baseConfig?.endpoint ?? 'https://api.github.com/' + (baseConfig?.platform === PLATFORM_TYPE_GITHUB + ? baseConfig?.endpoint + : null) ?? 'https://api.github.com/' ); if (presetName === 'default') { try { diff --git a/lib/config/presets/gitlab.spec.ts b/lib/config/presets/gitlab.spec.ts index f9f3373bb44074af41b337b3e2d8d7858136076a..88a3a00942838762c964cf2d0c29c5fbb4e24dac 100644 --- a/lib/config/presets/gitlab.spec.ts +++ b/lib/config/presets/gitlab.spec.ts @@ -1,11 +1,13 @@ +import { PartialDeep } from 'type-fest'; import * as gitlab from './gitlab'; import { api } from '../../platform/gitlab/gl-got-wrapper'; import { GotResponse } from '../../platform'; +import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; jest.mock('../../platform/gitlab/gl-got-wrapper'); jest.mock('../../util/got'); -const glGot: jest.Mock<Promise<Partial<GotResponse>>> = api.get as never; +const glGot: jest.Mock<Promise<PartialDeep<GotResponse>>> = api.get as never; describe('config/presets/gitlab', () => { beforeEach(() => { @@ -55,13 +57,20 @@ describe('config/presets/gitlab', () => { }); it('uses default endpoint', async () => { await gitlab.getPreset('some/repo', 'default').catch((_) => {}); + await gitlab + .getPreset('some/repo', 'default', { + endpoint: 'https://gitlab.example.org/api/v4', + }) + .catch((_) => {}); expect(glGot.mock.calls[0][0]).toEqual( 'https://gitlab.com/api/v4/projects/some%2Frepo/repository/branches' ); + expect(glGot.mock.calls).toMatchSnapshot(); }); it('uses custom endpoint', async () => { await gitlab .getPreset('some/repo', 'default', { + platform: PLATFORM_TYPE_GITLAB, endpoint: 'https://gitlab.example.org/api/v4', }) .catch((_) => {}); diff --git a/lib/config/presets/gitlab.ts b/lib/config/presets/gitlab.ts index b765c773e67bf18c3cbcb12ffa19e8a1b2e3db36..d2d7d9e78b99792252e17b2eeab62fd4437d803a 100644 --- a/lib/config/presets/gitlab.ts +++ b/lib/config/presets/gitlab.ts @@ -3,6 +3,7 @@ import { logger } from '../../logger'; import { Preset } from './common'; import { ensureTrailingSlash } from '../../util/url'; import { RenovateConfig } from '../common'; +import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; const { get: glGot } = api; @@ -35,7 +36,9 @@ export async function getPreset( baseConfig?: RenovateConfig ): Promise<Preset> { const endpoint = ensureTrailingSlash( - baseConfig?.endpoint ?? 'https://gitlab.com/api/v4/' + (baseConfig?.platform === PLATFORM_TYPE_GITLAB + ? baseConfig?.endpoint + : null) ?? 'https://gitlab.com/api/v4/' ); if (presetName !== 'default') { // TODO: proper error contructor