Skip to content

Commit a0cdaae

Browse files
refactor
1 parent 722aae0 commit a0cdaae

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/bitbucket/bitbucket-server/pullRequests.test.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
import { ServerPullRequestApi } from './pullRequests';
22
import { BitbucketSite } from '../model';
3-
import { IHTTPClient } from '../httpClient';
3+
4+
const mockGet = jest.fn();
5+
const mockPost = jest.fn();
6+
const mockPut = jest.fn();
7+
const mockDelete = jest.fn();
8+
jest.mock('../httpClient', () => ({
9+
HTTPClient: jest.fn().mockImplementation(() => ({
10+
get: mockGet,
11+
post: mockPost,
12+
put: mockPut,
13+
delete: mockDelete,
14+
})),
15+
}));
16+
import { HTTPClient } from '../httpClient';
17+
import { AxiosResponse } from 'axios';
418

519
describe('ServerPullRequestApi', () => {
620
let api: ServerPullRequestApi;
7-
let mockClient: jest.Mocked<IHTTPClient>;
21+
let mockClient: HTTPClient = new HTTPClient('', '', '', async (errJson: AxiosResponse) => Error('some error'));
822
let site: BitbucketSite;
923

1024
beforeEach(() => {
11-
mockClient = {
12-
get: jest.fn(),
13-
post: jest.fn(),
14-
put: jest.fn(),
15-
delete: jest.fn(),
16-
getRaw: jest.fn(),
17-
} as unknown as jest.Mocked<IHTTPClient>;
18-
25+
jest.clearAllMocks();
1926
api = new ServerPullRequestApi(mockClient);
2027
site = { ownerSlug: 'owner', repoSlug: 'repo', details: { userId: 'user' } } as BitbucketSite;
2128
});
2229

2330
it('should get with a v8 if no 404s', async () => {
24-
mockClient.get.mockImplementation((url) => {
31+
mockGet.mockImplementation((url) => {
2532
if (
2633
url.includes('/rest/api/1.0/projects/owner/repos/repo/pull-requests/PR-1/blocker-comments?count=true')
2734
) {
@@ -36,7 +43,7 @@ describe('ServerPullRequestApi', () => {
3643

3744
await api.get(site, 'PR-1');
3845

39-
expect(mockClient.get).lastCalledWith(
46+
expect(mockGet).lastCalledWith(
4047
'/rest/api/1.0/projects/owner/repos/repo/pull-requests/PR-1/blocker-comments?count=true',
4148
);
4249
});

0 commit comments

Comments
 (0)