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