@@ -12,7 +12,7 @@ describe('retryRequestHandler', () => {
1212 const requestConfig : InternalAxiosRequestConfig = { headers : { } as AxiosHeaders } ;
1313 const updatedConfig = retryRequestHandler ( requestConfig ) ;
1414
15- expect ( updatedConfig . retryCount ) . toBe ( 0 ) ;
15+ expect ( updatedConfig . retryCount ) . toBe ( 1 ) ;
1616 } ) ;
1717} ) ;
1818
@@ -40,40 +40,65 @@ describe('retryResponseErrorHandler', () => {
4040 it ( 'should reject the promise if retryOnError is false' , async ( ) => {
4141 const error = { config : { retryOnError : false } , code : 'ECONNABORTED' } ;
4242 const config = { retryLimit : 5 } ;
43-
44- await expect ( retryResponseErrorHandler ( error , config ) ) . rejects . toBe ( error ) ;
43+ const client = axios . create ( ) ;
44+
45+ try {
46+ await retryResponseErrorHandler ( error , config , client ) ;
47+ fail ( 'Expected retryResponseErrorHandler to throw an error' ) ;
48+ } catch ( err ) {
49+ expect ( err ) . toEqual ( expect . objectContaining ( {
50+ code : 'ECONNABORTED' ,
51+ config : expect . objectContaining ( { retryOnError : false } ) ,
52+ } ) ) ;
53+ }
4554 } ) ;
4655 it ( 'should reject the promise if retryOnError is true' , async ( ) => {
4756 const error = { config : { retryOnError : true } } ;
4857 const config = { retryLimit : 5 } ;
49-
50- await expect ( retryResponseErrorHandler ( error , config ) ) . rejects . toBe ( error ) ;
58+ const client = axios . create ( ) ;
59+
60+ try {
61+ await retryResponseErrorHandler ( error , config , client ) ;
62+ fail ( 'Expected retryResponseErrorHandler to throw an error' ) ;
63+ } catch ( err : any ) {
64+ expect ( err . config ) . toEqual ( expect . objectContaining ( { retryOnError : true } ) ) ;
65+ expect ( err ) . toEqual ( error ) ;
66+ }
5167 } ) ;
5268 it ( 'should resolve the promise to 408 error if retryOnError is true and error code is ECONNABORTED' , async ( ) => {
5369 const error = { config : { retryOnError : true , retryCount : 1 } , code : 'ECONNABORTED' } ;
5470 const config = { retryLimit : 5 , timeout : 1000 } ;
55-
56- const errorResponse = { status : 408 , statusText : 'timeout of 1000ms exceeded' } ;
57-
58- await expect ( retryResponseErrorHandler ( error , config ) ) . resolves . toEqual ( errorResponse ) ;
71+ const client = axios . create ( ) ;
72+ try {
73+ await retryResponseErrorHandler ( error , config , client ) ;
74+ fail ( 'Expected retryResponseErrorHandler to throw an error' ) ;
75+ } catch ( err ) {
76+ expect ( err ) . toEqual ( expect . objectContaining ( {
77+ error_code : 408 ,
78+ error_message : `Timeout of ${ config . timeout } ms exceeded` ,
79+ errors : null
80+ } ) ) ;
81+ }
5982 } ) ;
6083 it ( 'should reject the promise if response status is 429 and retryCount exceeds retryLimit' , async ( ) => {
6184 const error = {
6285 config : { retryOnError : true , retryCount : 5 } ,
6386 response : { status : 429 , statusText : 'timeout of 1000ms exceeded' } ,
6487 } ;
6588 const config = { retryLimit : 5 , timeout : 1000 } ;
89+ const client = axios . create ( ) ;
6690
67- await expect ( retryResponseErrorHandler ( error , config ) ) . rejects . toBe ( error ) ;
91+ await expect ( retryResponseErrorHandler ( error , config , client ) ) . rejects . toBe ( error ) ;
6892 } ) ;
6993 it ( 'should reject the promise if response status is 401 and retryCount exceeds retryLimit' , async ( ) => {
7094 const error = {
7195 config : { retryOnError : true , retryCount : 5 } ,
7296 response : { status : 401 , statusText : 'timeout of 1000ms exceeded' } ,
7397 } ;
7498 const config = { retryLimit : 5 , timeout : 1000 } ;
99+ const client = axios . create ( ) ;
75100
76- await expect ( retryResponseErrorHandler ( error , config ) ) . rejects . toBe ( error ) ;
101+ await expect ( retryResponseErrorHandler ( error , config , client ) ) . rejects . toBe ( error ) ;
77102 } ) ;
78103 it ( 'should reject the promise if response status is 429 or 401 and retryCount is within limit' , async ( ) => {
79104 const error = {
@@ -87,17 +112,24 @@ describe('retryResponseErrorHandler', () => {
87112 } ,
88113 } ;
89114 const config = { retryLimit : 5 , timeout : 1000 } ;
115+ const client = axios . create ( ) ;
90116
91117 const finalResponseObj = {
92- config : { retryOnError : true , retryCount : 5 } ,
118+ config : { retryOnError : true , retryCount : 4 } ,
93119 response : { status : 429 , statusText : 'timeout of 1000ms exceeded' } ,
94120 } ;
95121
96122 mock . onPost ( '/retryURL' ) . reply ( 200 , finalResponseObj ) ;
97123
98- const finalResponse = await retryResponseErrorHandler ( error , config ) ;
124+ try {
125+ await retryResponseErrorHandler ( error , config , client ) ;
126+ throw new Error ( 'Expected retryResponseErrorHandler to throw an error' ) ;
127+ } catch ( err : any ) {
128+ expect ( err . response . status ) . toBe ( 429 ) ;
129+ expect ( err . response . statusText ) . toBe ( error . response . statusText ) ;
130+ expect ( err . config . retryCount ) . toBe ( error . config . retryCount ) ;
131+ }
99132
100- expect ( finalResponse . data ) . toEqual ( finalResponseObj ) ;
101133 } ) ;
102134 it ( 'should call the retry function if retryCondition is passed' , async ( ) => {
103135 const error = {
@@ -113,6 +145,7 @@ describe('retryResponseErrorHandler', () => {
113145 // eslint-disable-next-line @typescript-eslint/no-shadow
114146 const retryCondition = ( error : any ) => true ;
115147 const config = { retryLimit : 5 , timeout : 1000 , retryCondition : retryCondition } ;
148+ const client = axios . create ( ) ;
116149
117150 const finalResponseObj = {
118151 config : { retryOnError : true , retryCount : 5 } ,
@@ -121,7 +154,7 @@ describe('retryResponseErrorHandler', () => {
121154
122155 mock . onPost ( '/retryURL' ) . reply ( 200 , finalResponseObj ) ;
123156
124- const finalResponse = await retryResponseErrorHandler ( error , config ) ;
157+ const finalResponse : any = await retryResponseErrorHandler ( error , config , client ) ;
125158
126159 expect ( finalResponse . data ) . toEqual ( finalResponseObj ) ;
127160 } ) ;
@@ -139,6 +172,7 @@ describe('retryResponseErrorHandler', () => {
139172 // eslint-disable-next-line @typescript-eslint/no-shadow
140173 const retryCondition = ( error : any ) => true ;
141174 const config = { retryLimit : 5 , timeout : 1000 , retryCondition : retryCondition } ;
175+ const client = axios . create ( ) ;
142176
143177 const finalResponseObj = {
144178 config : { retryOnError : true , retryCount : 5 } ,
@@ -147,6 +181,6 @@ describe('retryResponseErrorHandler', () => {
147181
148182 mock . onPost ( '/retryURL' ) . reply ( 200 , finalResponseObj ) ;
149183
150- await expect ( retryResponseErrorHandler ( error , config ) ) . rejects . toBe ( error ) ;
184+ await expect ( retryResponseErrorHandler ( error , config , client ) ) . rejects . toBe ( error ) ;
151185 } ) ;
152186} ) ;
0 commit comments