1 | import tap from 'tap'
|
2 |
|
3 | import { normalizeResponse } from '../lib/normalizeResponse'
|
4 |
|
5 | tap.test('normalizeResponse - string', async (t) => {
|
6 | const res = normalizeResponse('body')
|
7 | t.ok(res.headers && String(res.headers['Content-Type']).includes('text/html'))
|
8 | t.equal(res.body, 'body')
|
9 | })
|
10 |
|
11 | tap.test('normalizeResponse - html', async (t) => {
|
12 | const res = normalizeResponse({
|
13 | html: 'body',
|
14 | })
|
15 | t.ok(res.headers && String(res.headers['Content-Type']).includes('text/html'))
|
16 | t.equal(res.body, 'body')
|
17 | })
|
18 |
|
19 | tap.test('normalizeResponse - json', async (t) => {
|
20 | const json = { foo: true }
|
21 | const res = normalizeResponse({ json })
|
22 | t.ok(res.headers && String(res.headers['Content-Type']).includes('application/json'))
|
23 | t.equal(res.body, JSON.stringify(json))
|
24 | })
|
25 |
|
26 | tap.test('normalizeResponse - xml', async (t) => {
|
27 | const xml = '</>'
|
28 | const res = normalizeResponse({ xml })
|
29 | t.ok(res.headers && String(res.headers['Content-Type']).includes('application/xml'))
|
30 | t.equal(res.body, xml)
|
31 | })
|
32 |
|
33 | tap.test('normalizeResponse - statusCode', async (t) => {
|
34 | const res = normalizeResponse({ statusCode: 400 })
|
35 | t.equal(res.statusCode, 400)
|
36 | })
|
37 |
|
38 | tap.test('normalizeResponse - headers', async (t) => {
|
39 | const res = normalizeResponse({ headers: { Host: 'foo' } })
|
40 | t.ok(res.headers && res.headers.Host === 'foo')
|
41 | })
|
42 |
|
43 | tap.test('normalizeResponse - multiValueHeaders', async (t) => {
|
44 | const res = normalizeResponse({
|
45 | multiValueHeaders: { 'Set-Cookie': ['foo', 'bar'] },
|
46 | })
|
47 | t.ok(res.multiValueHeaders && res.multiValueHeaders['Set-Cookie'][0] === 'foo')
|
48 | })
|