Select Git revision
index.spec.ts
index.spec.ts 33.63 KiB
import * as _hostRules from '../../util/host-rules';
import {
REPOSITORY_ARCHIVED,
REPOSITORY_CHANGED,
REPOSITORY_DISABLED,
REPOSITORY_EMPTY,
REPOSITORY_MIRRORED,
} from '../../constants/error-messages';
import {
PR_STATE_NOT_OPEN,
PR_STATE_OPEN,
} from '../../constants/pull-requests';
import { BranchStatus } from '../../types';
import { GotResponse, Platform } from '..';
import { partial } from '../../../test/util';
describe('platform/gitlab', () => {
let gitlab: Platform;
let api: jest.Mocked<typeof import('./gl-got-wrapper').api>;
let hostRules: jest.Mocked<typeof _hostRules>;
let GitStorage: jest.Mocked<typeof import('../git/storage')> & jest.Mock;
beforeEach(async () => {
// reset module
jest.resetModules();
jest.resetAllMocks();
jest.mock('./gl-got-wrapper');
gitlab = await import('.');
api = require('./gl-got-wrapper').api;
jest.mock('../../util/host-rules');
hostRules = require('../../util/host-rules');
jest.mock('../git/storage');
GitStorage = require('../git/storage').Storage;
GitStorage.mockImplementation(() => ({
initRepo: jest.fn(),
cleanRepo: jest.fn(),
getFileList: jest.fn(),
branchExists: jest.fn(() => true),
isBranchStale: jest.fn(() => false),
setBaseBranch: jest.fn(),
getBranchLastCommitTime: jest.fn(),
getAllRenovateBranches: jest.fn(),
getCommitMessages: jest.fn(),
getFile: jest.fn(),
commitFilesToBranch: jest.fn(),
mergeBranch: jest.fn(),
deleteBranch: jest.fn(),
getRepoStatus: jest.fn(),
getBranchCommit: jest.fn(
() => '0d9c7726c3d628b7e28af234595cfd20febdbf8e'
),
}));
hostRules.find.mockReturnValue({
token: 'abc123',
});
});
afterEach(() => {
gitlab.cleanRepo();
});
describe('initPlatform()', () => {
it(`should throw if no token`, async () => {
await expect(gitlab.initPlatform({} as any)).rejects.toThrow();
});
it(`should throw if auth fails`, async () => {
// user
api.get.mockRejectedValueOnce(new Error('403'));
await expect(
gitlab.initPlatform({ token: 'some-token', endpoint: undefined })
).rejects.toThrow();