2020-09-30 19:06:03 +00:00
|
|
|
import { RenovateConfig, getConfig, git, mocked } from '../../../../test/util';
|
2020-03-05 20:57:24 +00:00
|
|
|
import * as _branchWorker from '../../branch';
|
2020-08-31 14:05:38 +00:00
|
|
|
import { BranchConfig, ProcessBranchResult } from '../../common';
|
2020-12-16 08:13:52 +00:00
|
|
|
import { Limit, isLimitReached } from '../../global/limits';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as _limits from './limits';
|
|
|
|
import { writeUpdates } from './write';
|
2020-01-06 08:16:15 +00:00
|
|
|
|
2020-09-30 19:06:03 +00:00
|
|
|
jest.mock('../../../util/git');
|
|
|
|
|
2020-01-06 08:16:15 +00:00
|
|
|
const branchWorker = mocked(_branchWorker);
|
|
|
|
const limits = mocked(_limits);
|
|
|
|
|
|
|
|
branchWorker.processBranch = jest.fn();
|
|
|
|
|
|
|
|
limits.getPrsRemaining = jest.fn().mockResolvedValue(99);
|
2021-01-10 12:29:14 +00:00
|
|
|
limits.getBranchesRemaining = jest.fn().mockReturnValue(99);
|
2020-01-06 08:16:15 +00:00
|
|
|
|
|
|
|
let config: RenovateConfig;
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
config = getConfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('workers/repository/write', () => {
|
|
|
|
describe('writeUpdates()', () => {
|
|
|
|
it('skips branches blocked by pin', async () => {
|
|
|
|
const branches: BranchConfig[] = [
|
|
|
|
{ updateType: 'pin' },
|
|
|
|
{ blockedByPin: true },
|
|
|
|
{},
|
|
|
|
] as never;
|
2020-09-30 19:06:03 +00:00
|
|
|
git.branchExists.mockReturnValueOnce(false);
|
2020-05-05 17:46:35 +00:00
|
|
|
const res = await writeUpdates(config, branches);
|
2020-01-06 08:16:15 +00:00
|
|
|
expect(res).toEqual('done');
|
|
|
|
expect(branchWorker.processBranch).toHaveBeenCalledTimes(2);
|
|
|
|
});
|
|
|
|
it('stops after automerge', async () => {
|
2020-05-18 19:37:47 +00:00
|
|
|
const branches: BranchConfig[] = [
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{ automergeType: 'pr-comment', requiredStatusChecks: null },
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
] as never;
|
2020-09-30 19:06:03 +00:00
|
|
|
git.branchExists.mockReturnValue(true);
|
2020-08-31 14:05:38 +00:00
|
|
|
branchWorker.processBranch.mockResolvedValueOnce(
|
|
|
|
ProcessBranchResult.PrCreated
|
|
|
|
);
|
|
|
|
branchWorker.processBranch.mockResolvedValueOnce(
|
|
|
|
ProcessBranchResult.AlreadyExisted
|
|
|
|
);
|
|
|
|
branchWorker.processBranch.mockResolvedValueOnce(
|
|
|
|
ProcessBranchResult.Automerged
|
|
|
|
);
|
|
|
|
branchWorker.processBranch.mockResolvedValueOnce(
|
|
|
|
ProcessBranchResult.Automerged
|
|
|
|
);
|
2020-05-05 17:46:35 +00:00
|
|
|
const res = await writeUpdates(config, branches);
|
2020-01-06 08:16:15 +00:00
|
|
|
expect(res).toEqual('automerged');
|
2020-05-18 19:37:47 +00:00
|
|
|
expect(branchWorker.processBranch).toHaveBeenCalledTimes(4);
|
2020-01-06 08:16:15 +00:00
|
|
|
});
|
2020-12-16 08:13:52 +00:00
|
|
|
it('increments branch counter', async () => {
|
|
|
|
const branches: BranchConfig[] = [{}] as never;
|
|
|
|
branchWorker.processBranch.mockResolvedValueOnce(
|
2021-01-10 12:29:14 +00:00
|
|
|
ProcessBranchResult.PrCreated
|
2020-10-14 11:47:57 +00:00
|
|
|
);
|
2020-12-16 08:13:52 +00:00
|
|
|
git.branchExists.mockReturnValueOnce(false);
|
|
|
|
git.branchExists.mockReturnValueOnce(true);
|
2021-01-10 12:29:14 +00:00
|
|
|
limits.getBranchesRemaining.mockReturnValueOnce(1);
|
|
|
|
expect(isLimitReached(Limit.Branches)).toBeFalse();
|
2020-12-16 08:13:52 +00:00
|
|
|
await writeUpdates({ config }, branches);
|
2021-01-10 12:29:14 +00:00
|
|
|
expect(isLimitReached(Limit.Branches)).toBeTrue();
|
2020-10-14 11:47:57 +00:00
|
|
|
});
|
2020-01-06 08:16:15 +00:00
|
|
|
});
|
|
|
|
});
|