2020-10-02 09:57:52 +00:00
|
|
|
import { RenovateConfig, getConfig, platform } from '../../../../test/util';
|
|
|
|
import {
|
|
|
|
REPOSITORY_DISABLED,
|
|
|
|
REPOSITORY_FORKED,
|
|
|
|
} from '../../../constants/error-messages';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { initApis } from './apis';
|
2017-11-05 04:45:49 +00:00
|
|
|
|
|
|
|
describe('workers/repository/init/apis', () => {
|
|
|
|
describe('initApis', () => {
|
2019-12-17 05:56:42 +00:00
|
|
|
let config: RenovateConfig;
|
2017-11-07 10:46:10 +00:00
|
|
|
beforeEach(() => {
|
2019-12-17 05:56:42 +00:00
|
|
|
config = { ...getConfig() };
|
2017-11-07 10:46:10 +00:00
|
|
|
config.errors = [];
|
|
|
|
config.warnings = [];
|
2018-04-09 04:08:39 +00:00
|
|
|
config.token = 'some-token';
|
2020-10-02 09:57:52 +00:00
|
|
|
delete config.optimizeForDisabled;
|
|
|
|
delete config.includeForks;
|
2017-11-07 10:46:10 +00:00
|
|
|
});
|
2020-12-07 09:14:46 +00:00
|
|
|
afterEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
2017-11-05 04:45:49 +00:00
|
|
|
it('runs', async () => {
|
2020-10-02 09:57:52 +00:00
|
|
|
platform.initRepo.mockResolvedValueOnce({
|
|
|
|
defaultBranch: 'master',
|
|
|
|
isFork: false,
|
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
const workerPlatformConfig = await initApis(config);
|
|
|
|
expect(workerPlatformConfig).toBeTruthy();
|
2017-11-07 10:46:10 +00:00
|
|
|
});
|
2020-10-02 09:57:52 +00:00
|
|
|
it('throws for disabled', async () => {
|
|
|
|
platform.initRepo.mockResolvedValueOnce({
|
|
|
|
defaultBranch: 'master',
|
|
|
|
isFork: false,
|
|
|
|
});
|
|
|
|
platform.getJsonFile.mockResolvedValueOnce({ enabled: false });
|
|
|
|
await expect(
|
|
|
|
initApis({
|
|
|
|
...config,
|
|
|
|
optimizeForDisabled: true,
|
|
|
|
})
|
|
|
|
).rejects.toThrow(REPOSITORY_DISABLED);
|
|
|
|
});
|
|
|
|
it('throws for forked', async () => {
|
|
|
|
platform.initRepo.mockResolvedValueOnce({
|
|
|
|
defaultBranch: 'master',
|
|
|
|
isFork: true,
|
|
|
|
});
|
|
|
|
platform.getJsonFile.mockResolvedValueOnce({ includeForks: false });
|
|
|
|
await expect(
|
|
|
|
initApis({
|
|
|
|
...config,
|
|
|
|
includeForks: false,
|
|
|
|
})
|
|
|
|
).rejects.toThrow(REPOSITORY_FORKED);
|
|
|
|
});
|
2020-12-07 09:14:46 +00:00
|
|
|
it('uses the onboardingConfigFileName if set', async () => {
|
|
|
|
platform.initRepo.mockResolvedValueOnce({
|
|
|
|
defaultBranch: 'master',
|
|
|
|
isFork: false,
|
|
|
|
});
|
|
|
|
platform.getJsonFile.mockResolvedValueOnce({ includeForks: false });
|
|
|
|
const workerPlatformConfig = await initApis({
|
|
|
|
...config,
|
|
|
|
optimizeForDisabled: true,
|
|
|
|
onboardingConfigFileName: '.github/renovate.json',
|
|
|
|
});
|
|
|
|
expect(workerPlatformConfig).toBeTruthy();
|
|
|
|
expect(workerPlatformConfig.onboardingConfigFileName).toBe(
|
|
|
|
'.github/renovate.json'
|
|
|
|
);
|
|
|
|
expect(platform.getJsonFile).toHaveBeenCalledWith(
|
|
|
|
'.github/renovate.json'
|
|
|
|
);
|
|
|
|
expect(platform.getJsonFile).not.toHaveBeenCalledWith('renovate.json');
|
|
|
|
});
|
|
|
|
it('falls back to "renovate.json" if onboardingConfigFileName is not set', async () => {
|
|
|
|
platform.initRepo.mockResolvedValueOnce({
|
|
|
|
defaultBranch: 'master',
|
|
|
|
isFork: false,
|
|
|
|
});
|
|
|
|
platform.getJsonFile.mockResolvedValueOnce({ includeForks: false });
|
|
|
|
const workerPlatformConfig = await initApis({
|
|
|
|
...config,
|
|
|
|
optimizeForDisabled: true,
|
|
|
|
onboardingConfigFileName: undefined,
|
|
|
|
});
|
|
|
|
expect(workerPlatformConfig).toBeTruthy();
|
|
|
|
expect(workerPlatformConfig.onboardingConfigFileName).toBeUndefined();
|
|
|
|
expect(platform.getJsonFile).toHaveBeenCalledWith('renovate.json');
|
|
|
|
});
|
|
|
|
it('falls back to "renovate.json" if onboardingConfigFileName is not valid', async () => {
|
|
|
|
platform.initRepo.mockResolvedValueOnce({
|
|
|
|
defaultBranch: 'master',
|
|
|
|
isFork: false,
|
|
|
|
});
|
|
|
|
platform.getJsonFile.mockResolvedValueOnce({ includeForks: false });
|
|
|
|
const workerPlatformConfig = await initApis({
|
|
|
|
...config,
|
|
|
|
optimizeForDisabled: true,
|
|
|
|
onboardingConfigFileName: 'foo.bar',
|
|
|
|
});
|
|
|
|
expect(workerPlatformConfig).toBeTruthy();
|
|
|
|
expect(workerPlatformConfig.onboardingConfigFileName).toBe('foo.bar');
|
|
|
|
expect(platform.getJsonFile).toHaveBeenCalledWith('renovate.json');
|
|
|
|
});
|
2017-11-05 04:45:49 +00:00
|
|
|
});
|
|
|
|
});
|