Skip to content

Commit

Permalink
test: clean up normalizeHttpResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
willfarrell committed Nov 8, 2023
1 parent 9b9f87f commit a1148d4
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions packages/util/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,24 @@ test('normalizeHttpResponse should not change response', async (t) => {
const request = {
response: { headers: {} }
}
normalizeHttpResponse(request)
t.deepEqual(request, { response: { statusCode: 500, headers: {} } })
const response = normalizeHttpResponse(request)
t.deepEqual(response, { statusCode: 500, headers: {} })
t.deepEqual(request, { response })
})
test('normalizeHttpResponse should update headers in response', async (t) => {
const request = {
response: {}
}
normalizeHttpResponse(request)
t.deepEqual(request, { response: { statusCode: 200, headers: {}, body: {} } })
const response = normalizeHttpResponse(request)
t.deepEqual(response, { statusCode: 200, headers: {}, body: {} })
t.deepEqual(request, { response })
})

test('normalizeHttpResponse should update undefined response', async (t) => {
const request = {}
normalizeHttpResponse(request)
t.deepEqual(request, { response: { statusCode: 500, headers: {} } })
const response = normalizeHttpResponse(request)
t.deepEqual(response, { statusCode: 500, headers: {} })
t.deepEqual(request, { response })
})

test('normalizeHttpResponse should update incomplete response', async (t) => {
Expand All @@ -582,33 +585,35 @@ test('normalizeHttpResponse should update incomplete response', async (t) => {
body: ''
}
}
normalizeHttpResponse(request)
t.deepEqual(request, { response: { statusCode: 500, headers: {}, body: '' } })
const response = normalizeHttpResponse(request)
t.deepEqual(response, { statusCode: 500, headers: {}, body: '' })
t.deepEqual(request, { response })
})

test('normalizeHttpResponse should update nullish response', async (t) => {
const request = {
response: null
}
normalizeHttpResponse(request)
t.deepEqual(request, {
response: { statusCode: 200, headers: {}, body: null }
})
const response = normalizeHttpResponse(request)
t.deepEqual(response, { statusCode: 200, headers: {}, body: null })
t.deepEqual(request, { response })
})

test('normalizeHttpResponse should update string response', async (t) => {
const request = {
response: ''
}
normalizeHttpResponse(request)
t.deepEqual(request, { response: { statusCode: 200, headers: {}, body: '' } })
const response = normalizeHttpResponse(request)
t.deepEqual(response, { statusCode: 200, headers: {}, body: '' })
t.deepEqual(request, { response })
})
test('normalizeHttpResponse should update array response', async (t) => {
const request = {
response: []
}
normalizeHttpResponse(request)
t.deepEqual(request, { response: { statusCode: 200, headers: {}, body: [] } })
const response = normalizeHttpResponse(request)
t.deepEqual(response, { statusCode: 200, headers: {}, body: [] })
t.deepEqual(request, { response })
})

// HttpError
Expand Down

0 comments on commit a1148d4

Please sign in to comment.