1
1
import { ServerPullRequestApi } from './pullRequests' ;
2
2
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' ;
4
18
5
19
describe ( 'ServerPullRequestApi' , ( ) => {
6
20
let api : ServerPullRequestApi ;
7
- let mockClient : jest . Mocked < IHTTPClient > ;
21
+ let mockClient : HTTPClient = new HTTPClient ( '' , '' , '' , async ( errJson : AxiosResponse ) => Error ( 'some error' ) ) ;
8
22
let site : BitbucketSite ;
9
23
10
24
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 ( ) ;
19
26
api = new ServerPullRequestApi ( mockClient ) ;
20
27
site = { ownerSlug : 'owner' , repoSlug : 'repo' , details : { userId : 'user' } } as BitbucketSite ;
21
28
} ) ;
22
29
23
30
it ( 'should get with a v8 if no 404s' , async ( ) => {
24
- mockClient . get . mockImplementation ( ( url ) => {
31
+ mockGet . mockImplementation ( ( url ) => {
25
32
if (
26
33
url . includes ( '/rest/api/1.0/projects/owner/repos/repo/pull-requests/PR-1/blocker-comments?count=true' )
27
34
) {
@@ -36,7 +43,7 @@ describe('ServerPullRequestApi', () => {
36
43
37
44
await api . get ( site , 'PR-1' ) ;
38
45
39
- expect ( mockClient . get ) . lastCalledWith (
46
+ expect ( mockGet ) . lastCalledWith (
40
47
'/rest/api/1.0/projects/owner/repos/repo/pull-requests/PR-1/blocker-comments?count=true' ,
41
48
) ;
42
49
} ) ;
0 commit comments