renovate/lib/platform/bitbucket/bb-got-wrapper.spec.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-03-05 20:57:24 +00:00
import { GotApi } from '../common';
import { PLATFORM_TYPE_BITBUCKET } from '../../constants/platforms';
describe('platform/gl-got-wrapper', () => {
2019-07-10 08:41:12 +00:00
let api: GotApi;
let got: jest.Mock<typeof import('got')>;
2020-03-05 20:57:24 +00:00
let hostRules: typeof import('../../util/host-rules');
beforeEach(() => {
// reset module
jest.resetAllMocks();
2020-03-05 20:57:24 +00:00
jest.mock('../../util/got');
got = require('../../util/got').api;
hostRules = require('../../util/host-rules');
api = require('./bb-got-wrapper').api;
// clean up hostRules
hostRules.clear();
hostRules.add({
2020-02-06 12:15:54 +00:00
hostType: PLATFORM_TYPE_BITBUCKET,
baseUrl: 'https://api.bitbucket.org',
token: 'token',
});
});
it('posts', async () => {
const body = ['a', 'b'];
got.mockImplementationOnce(
() =>
({
body,
} as any)
);
const res = await api.post('some-url');
expect(res.body).toEqual(body);
});
it('returns cached', async () => {
got.mockReturnValueOnce({
body: {},
} as any);
const res1 = await api.get('projects/foo');
2019-05-26 09:25:24 +00:00
expect(res1).toMatchSnapshot();
});
});