@@ -31,22 +31,25 @@ response200Blob.blob = jest.fn(() => blob);
3131
3232const quipService = new QuipService ( '###TOKEN###' , 'http://quip.com' ) ;
3333
34+ beforeEach ( ( ) => {
35+ quipService . stats . query_count = 0 ;
36+ quipService . querries503 = new Map ( ) ;
37+ } ) ;
38+
3439test ( 'constructor tests' , async ( ) => {
3540 expect ( quipService . accessToken ) . toBe ( '###TOKEN###' ) ;
3641 expect ( quipService . apiURL ) . toBe ( 'http://quip.com' ) ;
3742 expect ( quipService . logger ) . toBeInstanceOf ( LoggerAdapter ) ;
3843} ) ;
3944
4045test ( '_apiCall response with 503 code' , async ( ) => {
41- quipService . stats . query_count = 0 ;
4246 fetch . mockReturnValue ( Promise . resolve ( response200 ) ) . mockReturnValueOnce ( Promise . resolve ( response503 ) ) ;
4347 const res = await quipService . _apiCall ( '/someURL' ) ;
4448 expect ( res . data ) . toBe ( 123456 ) ;
4549 expect ( quipService . stats . query_count ) . toBe ( 2 ) ;
4650} ) ;
4751
4852test ( '_apiCall response with 503 code more than 10 times' , async ( ) => {
49- quipService . stats . query_count = 0 ;
5053 fetch . mockReturnValue ( Promise . resolve ( response503 ) ) ;
5154 const res = await quipService . _apiCall ( '/someURL' ) ;
5255 expect ( res ) . toBe ( undefined ) ;
@@ -69,15 +72,13 @@ test('_apiCall: fetch with exeption', async () => {
6972} ) ;
7073
7174test ( '_apiCallBlob response with 503 code' , async ( ) => {
72- quipService . stats . query_count = 0 ;
7375 fetch . mockReturnValue ( Promise . resolve ( response200Blob ) ) . mockReturnValueOnce ( Promise . resolve ( response503 ) ) ;
7476 const res = await quipService . _apiCallBlob ( '/someURL' ) ;
7577 expect ( res ) . toBe ( blob ) ;
7678 expect ( quipService . stats . query_count ) . toBe ( 2 ) ;
7779} ) ;
7880
7981test ( '_apiCallBlob response with 503 code more than 10 times' , async ( ) => {
80- quipService . stats . query_count = 0 ;
8182 fetch . mockReturnValue ( Promise . resolve ( response503 ) ) ;
8283 const res = await quipService . _apiCallBlob ( '/someURL' ) ;
8384 expect ( res ) . toBe ( undefined ) ;
0 commit comments