Skip to content

Commit ba390a5

Browse files
committed
test(sdk-middleware-http): test with retry for invalid json response
1 parent 5f723b9 commit ba390a5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/sdk-middleware-http/test/http.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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({

0 commit comments

Comments
 (0)