From d829b42d2bfb0a01938b5dcf53ae45cb7f646d61 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Fri, 23 Jul 2021 15:21:00 -0400 Subject: [PATCH 1/2] Test reply function returning array with body object --- tests/test_reply_function_sync.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_reply_function_sync.js b/tests/test_reply_function_sync.js index 83ead902b..c2302e8aa 100644 --- a/tests/test_reply_function_sync.js +++ b/tests/test_reply_function_sync.js @@ -319,6 +319,30 @@ describe('synchronous `reply()` function', () => { scope.done() }) + it('handles status code, object body, and headers object', async () => { + const exampleBody = { foo: 'bar' } + const scope = nock('http://example.test') + .get('/') + .reply(() => [ + 202, + exampleBody, + { 'x-key': 'value', 'x-key-2': 'value 2' }, + ]) + + const { statusCode, body, headers, rawHeaders } = await got( + 'http://example.test/' + ) + + expect(statusCode).to.equal(202) + expect(body).to.equal(JSON.stringify(exampleBody)) + expect(headers).to.deep.equal({ + 'x-key': 'value', + 'x-key-2': 'value 2', + }) + expect(rawHeaders).to.deep.equal(['x-key', 'value', 'x-key-2', 'value 2']) + scope.done() + }) + it('when given a non-array, raises the expected error', async () => { nock('http://example.test') .get('/abc') From bf09d41bf897fd9ade4a2fa09abb3554d9dc96f0 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Fri, 23 Jul 2021 15:24:18 -0400 Subject: [PATCH 2/2] Fix headers in test --- tests/test_reply_function_sync.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_reply_function_sync.js b/tests/test_reply_function_sync.js index c2302e8aa..cf36b23cc 100644 --- a/tests/test_reply_function_sync.js +++ b/tests/test_reply_function_sync.js @@ -336,10 +336,18 @@ describe('synchronous `reply()` function', () => { expect(statusCode).to.equal(202) expect(body).to.equal(JSON.stringify(exampleBody)) expect(headers).to.deep.equal({ + 'content-type': 'application/json', 'x-key': 'value', 'x-key-2': 'value 2', }) - expect(rawHeaders).to.deep.equal(['x-key', 'value', 'x-key-2', 'value 2']) + expect(rawHeaders).to.deep.equal([ + 'x-key', + 'value', + 'x-key-2', + 'value 2', + 'Content-Type', + 'application/json', + ]) scope.done() })