@@ -31,22 +31,25 @@ response200Blob.blob = jest.fn(() => blob);
31
31
32
32
const quipService = new QuipService ( '###TOKEN###' , 'http://quip.com' ) ;
33
33
34
+ beforeEach ( ( ) => {
35
+ quipService . stats . query_count = 0 ;
36
+ quipService . querries503 = new Map ( ) ;
37
+ } ) ;
38
+
34
39
test ( 'constructor tests' , async ( ) => {
35
40
expect ( quipService . accessToken ) . toBe ( '###TOKEN###' ) ;
36
41
expect ( quipService . apiURL ) . toBe ( 'http://quip.com' ) ;
37
42
expect ( quipService . logger ) . toBeInstanceOf ( LoggerAdapter ) ;
38
43
} ) ;
39
44
40
45
test ( '_apiCall response with 503 code' , async ( ) => {
41
- quipService . stats . query_count = 0 ;
42
46
fetch . mockReturnValue ( Promise . resolve ( response200 ) ) . mockReturnValueOnce ( Promise . resolve ( response503 ) ) ;
43
47
const res = await quipService . _apiCall ( '/someURL' ) ;
44
48
expect ( res . data ) . toBe ( 123456 ) ;
45
49
expect ( quipService . stats . query_count ) . toBe ( 2 ) ;
46
50
} ) ;
47
51
48
52
test ( '_apiCall response with 503 code more than 10 times' , async ( ) => {
49
- quipService . stats . query_count = 0 ;
50
53
fetch . mockReturnValue ( Promise . resolve ( response503 ) ) ;
51
54
const res = await quipService . _apiCall ( '/someURL' ) ;
52
55
expect ( res ) . toBe ( undefined ) ;
@@ -69,15 +72,13 @@ test('_apiCall: fetch with exeption', async () => {
69
72
} ) ;
70
73
71
74
test ( '_apiCallBlob response with 503 code' , async ( ) => {
72
- quipService . stats . query_count = 0 ;
73
75
fetch . mockReturnValue ( Promise . resolve ( response200Blob ) ) . mockReturnValueOnce ( Promise . resolve ( response503 ) ) ;
74
76
const res = await quipService . _apiCallBlob ( '/someURL' ) ;
75
77
expect ( res ) . toBe ( blob ) ;
76
78
expect ( quipService . stats . query_count ) . toBe ( 2 ) ;
77
79
} ) ;
78
80
79
81
test ( '_apiCallBlob response with 503 code more than 10 times' , async ( ) => {
80
- quipService . stats . query_count = 0 ;
81
82
fetch . mockReturnValue ( Promise . resolve ( response503 ) ) ;
82
83
const res = await quipService . _apiCallBlob ( '/someURL' ) ;
83
84
expect ( res ) . toBe ( undefined ) ;
0 commit comments