Skip to content

Commit

Permalink
Merge pull request #1622 from OlofMoriya/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude authored Sep 22, 2020
2 parents b6e6bb7 + 05d2609 commit 04f4f1f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/sdk-middleware-http/src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ export default function createHttpMiddleware({
return
}

res.json().then((result: Object) => {
res.text().then((result: Object) => {
const parsedResponse: Object = {
...response,
body: result,
body: result.length > 0 ? JSON.parse(result) : {},
statusCode: res.status,
}

Expand Down
30 changes: 30 additions & 0 deletions packages/sdk-middleware-http/test/http.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,4 +952,34 @@ describe('Http', () => {

httpMiddleware(next)(request, response)
}))

test('execute a post request with empty 202 response', () =>
new Promise((resolve, reject) => {
const request = createTestRequest({
uri: '/foo/bar',
method: 'POST',
})
const response = { resolve, reject }
const next = (req, res) => {
expect(res).toEqual({
...response,
body: {},
statusCode: 202,
})
resolve()
}
// Use default options
const httpMiddleware = createHttpMiddleware({
host: testHost,
fetch,
})
nock(testHost)
.defaultReplyHeaders({
'Content-Type': 'application/json',
})
.post('/foo/bar')
.reply(202, undefined)

httpMiddleware(next)(request, response)
}))
})

0 comments on commit 04f4f1f

Please sign in to comment.