summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-03-15 12:51:58 -0300
committerEuAndreh <eu@euandre.org>2024-03-15 12:51:58 -0300
commit631ad28b1f7bd46a18fa477eec09af7d4746573f (patch)
treed18661c77470cb37cc00cd67bfe4a513ee6dbbb4 /tests
parentsrc/hero.mjs: Add emitHeaders() (diff)
downloadpapod-631ad28b1f7bd46a18fa477eec09af7d4746573f.tar.gz
papod-631ad28b1f7bd46a18fa477eec09af7d4746573f.tar.xz
src/hero.mjs: Add buildHttpPayload()
Diffstat (limited to 'tests')
-rw-r--r--tests/js/hero.mjs48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs
index d57152f..627aa33 100644
--- a/tests/js/hero.mjs
+++ b/tests/js/hero.mjs
@@ -32,6 +32,7 @@ import {
make404Handler,
handleRequest,
emitHeaders,
+ buildHttpPayload,
makeRequestListener,
actionsFn,
lineHandlerFn,
@@ -1165,6 +1166,52 @@ const test_emitHeaders = async t => {
});
};
+const test_buildHttpPayload = async t => {
+ t.start("buildHttpPayload()");
+
+ await t.test("empty values", () => {
+ assert.equal(
+ buildHttpPayload(404),
+ "HTTP/1.1 404 Not Found\r\n" +
+ "Connection: close\r\n" +
+ "Content-Length: 10\r\n" +
+ "Content-Type: text/plain; charset=UTF-8\r\n" +
+ "\r\n" +
+ "Not Found\n",
+ );
+ assert.equal(
+ buildHttpPayload(405),
+ "HTTP/1.1 405 Method Not Allowed\r\n" +
+ "Connection: close\r\n" +
+ "Content-Length: 19\r\n" +
+ "Content-Type: text/plain; charset=UTF-8\r\n" +
+ "\r\n" +
+ "Method Not Allowed\n",
+ );
+ });
+
+ await t.test("we can add headers and customise the message", () => {
+ assert.equal(
+ buildHttpPayload(404, {
+ headers: {
+ "X-Something": "something",
+ "Aaaa": "ZzZz",
+ "Content-Type": "text/plain",
+ },
+ message: "the message\n"
+ }),
+ "HTTP/1.1 404 Not Found\r\n" +
+ "Aaaa: ZzZz\r\n" +
+ "Connection: close\r\n" +
+ "Content-Length: 12\r\n" +
+ "Content-Type: text/plain\r\n" +
+ "X-Something: something\r\n" +
+ "\r\n" +
+ "the message\n",
+ );
+ });
+};
+
const test_makeRequestListener = async t => {
t.start("makeRequestListener()");
@@ -1858,6 +1905,7 @@ await runner.runTests([
test_make404Handler,
test_handleRequest,
test_emitHeaders,
+ test_buildHttpPayload,
test_makeRequestListener,
test_actionsFn,
test_lineHandlerFn,