renovate/test/workers/branch/automerge.spec.js
Rhys Arkins ea9ace2a76 feat: branch worker updates (#736)
This is a major refactor of branch code to prepare for Yarn workspaces plus creating PRs for branches with failing lockfiles. Marked as "feature" to cause a minor version bump due to the moderate chance of accidentally breaking something.
2017-08-26 16:10:18 +02:00

46 lines
1.7 KiB
JavaScript

const { tryBranchAutomerge } = require('../../../lib/workers/branch/automerge');
const defaultConfig = require('../../../lib/config/defaults').getConfig();
const logger = require('../../_fixtures/logger');
describe('workers/branch/automerge', () => {
describe('tryBranchAutomerge', () => {
let config;
beforeEach(() => {
config = {
...defaultConfig,
api: { getBranchStatus: jest.fn(), mergeBranch: jest.fn() },
logger,
};
});
it('returns false if not configured for automerge', async () => {
config.automerge = false;
expect(await tryBranchAutomerge(config)).toBe(false);
});
it('returns false if automergType is pr', async () => {
config.automerge = true;
config.automergeType = 'pr';
expect(await tryBranchAutomerge(config)).toBe(false);
});
it('returns false if branch status is not success', async () => {
config.automerge = true;
config.automergeType = 'branch-push';
config.api.getBranchStatus.mockReturnValueOnce('pending');
expect(await tryBranchAutomerge(config)).toBe(false);
});
it('returns false if automerge fails', async () => {
config.automerge = true;
config.automergeType = 'branch-push';
config.api.getBranchStatus.mockReturnValueOnce('success');
config.api.mergeBranch.mockImplementationOnce(() => {
throw new Error('merge error');
});
expect(await tryBranchAutomerge(config)).toBe(false);
});
it('returns true if automerge succeeds', async () => {
config.automerge = true;
config.automergeType = 'branch-push';
config.api.getBranchStatus.mockReturnValueOnce('success');
expect(await tryBranchAutomerge(config)).toBe(true);
});
});
});