mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
00c56d8bde
* chore: fix types * fix more types * chore: mote fixes * fix frmat * chore: fix tests * chore: fix type * chore: cleanup * chore: cleanup Co-authored-by: Rhys Arkins <rhys@arkins.net>
75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
import { RenovateConfig } from '../../config';
|
|
import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms';
|
|
import * as platform from '../../platform';
|
|
import * as _ghApi from '../../platform/github';
|
|
import * as _hostRules from '../../util/host-rules';
|
|
import { autodiscoverRepositories } from './autodiscover';
|
|
|
|
jest.mock('../../platform/github');
|
|
jest.unmock('../../platform');
|
|
|
|
// imports are readonly
|
|
const hostRules = _hostRules;
|
|
const ghApi: jest.Mocked<typeof _ghApi> = _ghApi as never;
|
|
|
|
describe('lib/workers/global/autodiscover', () => {
|
|
let config: RenovateConfig;
|
|
beforeEach(async () => {
|
|
jest.resetAllMocks();
|
|
config = {};
|
|
await platform.initPlatform({
|
|
platform: PLATFORM_TYPE_GITHUB,
|
|
token: 'abc123',
|
|
endpoint: 'endpoint',
|
|
});
|
|
});
|
|
it('returns if not autodiscovering', async () => {
|
|
expect(await autodiscoverRepositories(config)).toEqual(config);
|
|
});
|
|
it('autodiscovers github but empty', async () => {
|
|
config.autodiscover = true;
|
|
config.platform = PLATFORM_TYPE_GITHUB;
|
|
hostRules.find = jest.fn(() => ({
|
|
token: 'abc',
|
|
}));
|
|
ghApi.getRepos = jest.fn(() => Promise.resolve([]));
|
|
const res = await autodiscoverRepositories(config);
|
|
expect(res).toEqual(config);
|
|
});
|
|
it('autodiscovers github repos', async () => {
|
|
config.autodiscover = true;
|
|
config.platform = PLATFORM_TYPE_GITHUB;
|
|
hostRules.find = jest.fn(() => ({
|
|
token: 'abc',
|
|
}));
|
|
ghApi.getRepos = jest.fn(() => Promise.resolve(['a', 'b']));
|
|
const res = await autodiscoverRepositories(config);
|
|
expect(res.repositories).toHaveLength(2);
|
|
});
|
|
it('filters autodiscovered github repos', async () => {
|
|
config.autodiscover = true;
|
|
config.autodiscoverFilter = 'project/re*';
|
|
config.platform = PLATFORM_TYPE_GITHUB;
|
|
hostRules.find = jest.fn(() => ({
|
|
token: 'abc',
|
|
}));
|
|
ghApi.getRepos = jest.fn(() =>
|
|
Promise.resolve(['project/repo', 'project/another-repo'])
|
|
);
|
|
const res = await autodiscoverRepositories(config);
|
|
expect(res.repositories).toEqual(['project/repo']);
|
|
});
|
|
it('filters autodiscovered github repos but nothing matches', async () => {
|
|
config.autodiscover = true;
|
|
config.autodiscoverFilter = 'project/re*';
|
|
config.platform = 'github';
|
|
hostRules.find = jest.fn(() => ({
|
|
token: 'abc',
|
|
}));
|
|
ghApi.getRepos = jest.fn(() =>
|
|
Promise.resolve(['another-project/repo', 'another-project/another-repo'])
|
|
);
|
|
const res = await autodiscoverRepositories(config);
|
|
expect(res).toEqual(config);
|
|
});
|
|
});
|