/
check.spec.ts
67 lines (61 loc) · 2.08 KB
/
check.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {
RenovateConfig,
git,
mocked,
partial,
platform,
} from '../../../../../test/util';
import { REPOSITORY_CLOSED_ONBOARDING } from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import type { Pr } from '../../../../modules/platform/types';
import * as _cache from '../../../../util/cache/repository';
import { isOnboarded } from './check';
jest.mock('../../../../util/cache/repository');
jest.mock('../../../../util/git');
const cache = mocked(_cache);
describe('workers/repository/onboarding/branch/check', () => {
const config = partial<RenovateConfig>({
requireConfig: 'required',
suppressNotifications: [],
onboarding: true,
});
it('skips normal onboarding check if onboardingCache is valid', async () => {
cache.getCache.mockReturnValueOnce({
onboardingBranchCache: {
onboardingBranch: 'configure/renovate',
defaultBranchSha: 'default-sha',
onboardingBranchSha: 'onboarding-sha',
},
});
git.getBranchCommit
.mockReturnValueOnce('default-sha')
.mockReturnValueOnce('onboarding-sha');
const res = await isOnboarded(config);
expect(res).toBeFalse();
expect(logger.debug).toHaveBeenCalledWith(
'Onboarding cache is valid. Repo is not onboarded'
);
});
it('continues with normal logic if onboardingCache is invalid', async () => {
cache.getCache.mockReturnValueOnce({
onboardingBranchCache: {
onboardingBranch: 'configure/renovate',
defaultBranchSha: 'default-sha',
onboardingBranchSha: 'onboarding-sha',
},
});
git.getFileList.mockResolvedValue([]);
await isOnboarded(config);
expect(logger.debug).not.toHaveBeenCalledWith(
'Onboarding cache is valid. Repo is not onboarded'
);
});
it('continues with normal logic if closedPr exists', async () => {
cache.getCache.mockReturnValue({});
platform.findPr.mockResolvedValue(partial<Pr>());
git.getFileList.mockResolvedValue([]);
await expect(isOnboarded(config)).rejects.toThrow(
REPOSITORY_CLOSED_ONBOARDING
);
});
});