diff options
author | EuAndreh <eu@euandre.org> | 2024-03-16 05:38:17 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-03-16 05:38:17 -0300 |
commit | a03abe678afd45e9d139e13c9d17a569c2853547 (patch) | |
tree | c1703f22703ed878f1d9af0f4ba1d333e9d8ad2d /tests | |
parent | src/hero.mjs: Include stacktrace in 500 log entry (diff) | |
download | papod-a03abe678afd45e9d139e13c9d17a569c2853547.tar.gz papod-a03abe678afd45e9d139e13c9d17a569c2853547.tar.xz |
src/hero.mjs: interceptors.contentType(): Generate body from status when missing
Diffstat (limited to 'tests')
-rw-r--r-- | tests/js/hero.mjs | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index 1c34738..8d8f811 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -247,7 +247,7 @@ const test_interceptorsFn = async t => { assert.deepEqual( contents.map(o => u.dissoc(o, "timings")), [ - { ...req, type: "in-request" }, + { ...req, type: "in-request" }, { id: req.id, status, type: "in-response" }, ], ); @@ -261,20 +261,31 @@ const test_interceptorsFn = async t => { t.start("interceptorsFn().contentType()"); await t.test("empty values", async () => { + await assert.rejects( + async () => await interceptorsFn().contentType({}, next), + assert.AssertionError, + ); assert.deepEqual( - await interceptorsFn().contentType({}, next), + await interceptorsFn().contentType({ + status: 202, + }, next), { - body: "", + status: 202, + body: "Accepted\n", headers: { - "Content-Type": "application/json", - "Content-Length": 0, + "Content-Type": "text/plain", + "Content-Length": 9, }, }, ); assert.deepEqual( - await interceptorsFn().contentType({ body: "" }, next), + await interceptorsFn().contentType({ + status: 200, + body: "", + }, next), { + status: 200, body: "", headers: { "Content-Type": "text/html", @@ -286,8 +297,12 @@ const test_interceptorsFn = async t => { await t.test("body values", async () => { assert.deepEqual( - await interceptorsFn().contentType({ body: { a: 1 }}, next), + await interceptorsFn().contentType({ + status: 201, + body: { a: 1 }, + }, next), { + status: 201, body: `{"a":1}`, headers: { "Content-Type": "application/json", @@ -297,8 +312,12 @@ const test_interceptorsFn = async t => { ); assert.deepEqual( - await interceptorsFn().contentType({ body: "<br />" }, next), + await interceptorsFn().contentType({ + status: 200, + body: "<br />", + }, next), { + status: 200, body: "<br />", headers: { "Content-Type": "text/html", @@ -311,6 +330,7 @@ const test_interceptorsFn = async t => { await t.test("header values preference", async () => { assert.deepEqual( await interceptorsFn().contentType({ + status: 503, body: "", headers: { "Content-Type": "we have preference", @@ -318,6 +338,7 @@ const test_interceptorsFn = async t => { }, }, next), { + status: 503, body: "", headers: { "Content-Type": "we have preference", @@ -330,12 +351,14 @@ const test_interceptorsFn = async t => { await t.test("headers get propagated", async () => { assert.deepEqual( await interceptorsFn().contentType({ + status: 500, body: "", headers: { "My": "Header", }, }, next), { + status: 500, body: "", headers: { "My": "Header", |