/
automerge.spec.ts
71 lines (69 loc) · 2.79 KB
/
automerge.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
68
69
70
71
import { defaultConfig, git, platform } from '../../../test/util';
import { RenovateConfig } from '../../config';
import { setAdminConfig } from '../../config/admin';
import { BranchStatus } from '../../types';
import { tryBranchAutomerge } from './automerge';
jest.mock('../../util/git');
describe('workers/branch/automerge', () => {
describe('tryBranchAutomerge', () => {
let config: RenovateConfig;
beforeEach(() => {
config = {
...defaultConfig,
};
setAdminConfig();
});
it('returns false if not configured for automerge', async () => {
config.automerge = false;
expect(await tryBranchAutomerge(config)).toBe('no automerge');
});
it('returns false if automergeType is pr', async () => {
config.automerge = true;
config.automergeType = 'pr';
expect(await tryBranchAutomerge(config)).toBe('no automerge');
});
it('returns false if branch status is not success', async () => {
config.automerge = true;
config.automergeType = 'branch';
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow);
expect(await tryBranchAutomerge(config)).toBe('no automerge');
});
it('returns branch status error if branch status is failure', async () => {
config.automerge = true;
config.automergeType = 'branch';
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.red);
expect(await tryBranchAutomerge(config)).toBe('branch status error');
});
it('returns false if PR exists', async () => {
platform.getBranchPr.mockResolvedValueOnce({} as never);
config.automerge = true;
config.automergeType = 'branch';
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
expect(await tryBranchAutomerge(config)).toBe(
'automerge aborted - PR exists'
);
});
it('returns false if automerge fails', async () => {
config.automerge = true;
config.automergeType = 'branch';
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
git.mergeBranch.mockImplementationOnce(() => {
throw new Error('merge error');
});
expect(await tryBranchAutomerge(config)).toBe('failed');
});
it('returns true if automerge succeeds', async () => {
config.automerge = true;
config.automergeType = 'branch';
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
expect(await tryBranchAutomerge(config)).toBe('automerged');
});
it('returns true if automerge succeeds (dry-run)', async () => {
config.automerge = true;
config.automergeType = 'branch';
setAdminConfig({ dryRun: true });
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
expect(await tryBranchAutomerge(config)).toBe('automerged');
});
});
});