Select Git revision
package-controller
index.spec.js 8.39 KiB
const branchWorker = require('../../../lib/workers/branch');
const defaultConfig = require('../../../lib/config/defaults').getConfig();
const schedule = require('../../../lib/workers/branch/schedule');
const checkExisting = require('../../../lib/workers/branch/check-existing');
const parent = require('../../../lib/workers/branch/parent');
const manager = require('../../../lib/manager');
const lockFiles = require('../../../lib/workers/branch/lock-files');
const commit = require('../../../lib/workers/branch/commit');
const statusChecks = require('../../../lib/workers/branch/status-checks');
const automerge = require('../../../lib/workers/branch/automerge');
const prWorker = require('../../../lib/workers/pr');
jest.mock('../../../lib/manager');
jest.mock('../../../lib/workers/branch/schedule');
jest.mock('../../../lib/workers/branch/check-existing');
jest.mock('../../../lib/workers/branch/parent');
jest.mock('../../../lib/workers/branch/lock-files');
jest.mock('../../../lib/workers/branch/commit');
jest.mock('../../../lib/workers/branch/status-checks');
jest.mock('../../../lib/workers/branch/automerge');
jest.mock('../../../lib/workers/pr');
const logger = require('../../_fixtures/logger');
describe('workers/branch', () => {
describe('processBranch', () => {
let config;
beforeEach(() => {
prWorker.ensurePr = jest.fn();
prWorker.checkAutoMerge = jest.fn();
config = {
...defaultConfig,
errors: [],
warnings: [],
logger,
upgrades: [{ depName: 'some-dep-name' }],
};
schedule.isScheduledNow.mockReturnValue(true);
});
afterEach(() => {
platform.ensureComment.mockClear();
platform.ensureCommentRemoval.mockClear();
});
it('skips branch if not scheduled and branch does not exist', async () => {
schedule.isScheduledNow.mockReturnValueOnce(false);
await branchWorker.processBranch(config);
expect(checkExisting.prAlreadyExisted.mock.calls).toHaveLength(0);
});
it('skips branch if not scheduled and not updating out of schedule', async () => {
schedule.isScheduledNow.mockReturnValueOnce(false);
config.updateNotScheduled = false;
platform.branchExists.mockReturnValueOnce(true);
await branchWorker.processBranch(config);
expect(checkExisting.prAlreadyExisted.mock.calls).toHaveLength(0);
});
it('skips branch if closed major PR found', async () => {
schedule.isScheduledNow.mockReturnValueOnce(false);
platform.branchExists.mockReturnValueOnce(true);
config.isMajor = true;
checkExisting.prAlreadyExisted.mockReturnValueOnce({ number: 13 });
await branchWorker.processBranch(config);
expect(parent.getParentBranch.mock.calls.length).toBe(0);
expect(config.logger.error.mock.calls).toHaveLength(0);
});
it('skips branch if closed digest PR found', async () => {
schedule.isScheduledNow.mockReturnValueOnce(false);
platform.branchExists.mockReturnValueOnce(true);
config.isDigest = true;
checkExisting.prAlreadyExisted.mockReturnValueOnce({ number: 13 });