File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
packages/sdk-middleware-http/test Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,43 @@ describe('Http', () => {
9999 httpMiddleware ( next ) ( request , response )
100100 } ) )
101101
102+ test ( "execute a get request which doesn't return a json response with retry" , ( ) =>
103+ new Promise ( ( resolve , reject ) => {
104+ const request = createTestRequest ( {
105+ uri : '/foo/bar' ,
106+ } )
107+ const response = { resolve, reject }
108+ const next = ( req , res ) => {
109+ expect ( res ) . toEqual ( {
110+ ...response ,
111+ body : { foo : 'bar' } ,
112+ statusCode : 200 ,
113+ } )
114+ resolve ( )
115+ }
116+ // Use default options
117+ const httpMiddleware = createHttpMiddleware ( {
118+ host : testHost ,
119+ fetch,
120+ enableRetry : true ,
121+ } )
122+ nock ( testHost )
123+ . defaultReplyHeaders ( {
124+ 'Content-Type' : 'application/json' ,
125+ } )
126+ . get ( '/foo/bar' )
127+ . reply ( 200 , 'not json response' )
128+
129+ nock ( testHost )
130+ . defaultReplyHeaders ( {
131+ 'Content-Type' : 'application/json' ,
132+ } )
133+ . get ( '/foo/bar' )
134+ . reply ( 200 , { foo : 'bar' } )
135+
136+ httpMiddleware ( next ) ( request , response )
137+ } ) )
138+
102139 test ( 'execute a get request with timeout (success)' , ( ) =>
103140 new Promise ( ( resolve , reject ) => {
104141 const request = createTestRequest ( {
You can’t perform that action at this time.
0 commit comments