Select Git revision
index.spec.ts 39.11 KiB
import * as httpMock from '../../../../test/http-mock';
import type { logger as _logger } from '../../../logger';
import { BranchStatus, PrState } from '../../../types';
import type * as _git from '../../../util/git';
import { setBaseUrl } from '../../../util/http/bitbucket';
import type { Platform, RepoParams } from '../types';
const baseUrl = 'https://api.bitbucket.org';
const pr = {
id: 5,
source: { branch: { name: 'branch' } },
destination: { branch: { name: 'master' } },
title: 'title',
summary: { raw: 'summary' },
state: 'OPEN',
created_on: '2018-07-02T07:02:25.275030+00:00',
};
describe('modules/platform/bitbucket/index', () => {
let bitbucket: Platform;
let hostRules: jest.Mocked<typeof import('../../../util/host-rules')>;
let git: jest.Mocked<typeof _git>;
let logger: jest.Mocked<typeof _logger>;
beforeEach(async () => {
// reset module
jest.resetModules();
jest.mock('../../../util/git');
jest.mock('../../../util/host-rules');
jest.mock('../../../logger');
hostRules = require('../../../util/host-rules');
bitbucket = await import('.');
logger = (await import('../../../logger')).logger as any;
git = require('../../../util/git');
git.branchExists.mockReturnValue(true);
git.isBranchBehindBase.mockResolvedValue(false);
// clean up hostRules
hostRules.clear();
hostRules.find.mockReturnValue({
username: 'abc',
password: '123',
});
setBaseUrl(baseUrl);
});
async function initRepoMock(
config?: Partial<RepoParams>,
repoResp?: any,
existingScope?: httpMock.Scope
): Promise<httpMock.Scope> {
const repository = config?.repository ?? 'some/repo';
const scope = existingScope ?? httpMock.scope(baseUrl);
scope.get(`/2.0/repositories/${repository}`).reply(200, {
owner: {},
mainbranch: { name: 'master' },
...repoResp,
});
await bitbucket.initRepo({
repository: 'some/repo',
...config,
});
return scope;
}