@@ -92,4 +92,33 @@ describe('makeStelaApiCall', () => {
9292 expect ( responseBody ) . toEqual ( 'it worked' ) ;
9393 expect ( mock . isDone ( ) ) . toBe ( true ) ; // All mocked responses were invoked
9494 } ) ;
95+
96+ it ( 'should retry additional times than the default if configured to do so' , async ( ) => {
97+ const mock = nock ( 'https://api.permanent.local' )
98+ . get ( '/api/v2/testing' )
99+ . reply ( 404 , 'it did not work' )
100+ . get ( '/api/v2/testing' )
101+ . reply ( 404 , 'it did not work' )
102+ . get ( '/api/v2/testing' )
103+ . reply ( 404 , 'it did not work' )
104+ . get ( '/api/v2/testing' )
105+ . reply ( 404 , 'it did not work' )
106+ . get ( '/api/v2/testing' )
107+ . reply ( 200 , 'it worked' ) ;
108+
109+ const response = await makeStelaApiCall (
110+ {
111+ bearerToken : '12345' ,
112+ stelaBaseUrl : 'https://api.permanent.local/api/v2' ,
113+ retryOn : [ 404 ] ,
114+ retries : 4 ,
115+ retryDelay : ( attempt ) => attempt * 0.01 ,
116+ } ,
117+ '/testing' ,
118+ ) ;
119+ const responseBody = await response . text ( ) ;
120+
121+ expect ( responseBody ) . toEqual ( 'it worked' ) ;
122+ expect ( mock . isDone ( ) ) . toBe ( true ) ; // All mocked responses were invoked
123+ } ) ;
95124} ) ;
0 commit comments