diff options
author | EuAndreh <eu@euandre.org> | 2024-03-16 06:36:05 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-03-16 06:36:05 -0300 |
commit | cac533d1cc73ccd2659beb87c146254ed2887c9b (patch) | |
tree | 72dec38a2f65c0814ed14fb401c97dbebe54df53 /tests | |
parent | src/hero.mjs: findHandler(): learn how to find upgrade routes (diff) | |
download | papod-cac533d1cc73ccd2659beb87c146254ed2887c9b.tar.gz papod-cac533d1cc73ccd2659beb87c146254ed2887c9b.tar.xz |
src/hero.mjs: Remove current makeUpgradeListener() and its helpers
Diffstat (limited to 'tests')
-rw-r--r-- | tests/js/hero.mjs | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index 7a5738d..468f4a8 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -36,12 +36,6 @@ import { handle404, make404Handler, handleRequest, - emitHeaders, - buildHttpPayload, - fallback404Handler, - fallback405Handler, - handlerForConnection, - makeUpgradeListener, makeRequestListener, actionsFn, lineHandlerFn, @@ -1456,168 +1450,6 @@ const test_handleRequest = async t => { }); }; -const test_emitHeaders = async t => { - t.start("emitHeaders()"); - - await t.test("empty values", () => { - assert.equal(emitHeaders({}), ""); - assert.equal(emitHeaders({ "": "" }), ": "); - assert.equal(emitHeaders({ " ": " " }), " : "); - assert.equal(emitHeaders({ "_": "_" }), "_: _"); - }); - - await t.test("newlines are forwarded", () => { - assert.equal(emitHeaders({"\na\n": "\nb\n"}), "\na\n: \nb\n"); - }); - - await t.test("keys are always sorted", () => { - assert.equal( - emitHeaders({ "a": "one", "Z": "two" }), - "a: one\r\nZ: two", - ); - }); -}; - -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", - ); - }); -}; - -export const test_handlerForConnection = async t => { - t.start("handlerForConnection()"); - - await t.test("405 handler no matter the table when not GET method", () => { - assert.equal( - handlerForConnection(null, "POST", null), - fallback405Handler, - ); - }); - - await t.test("404 handler when there is no route", () => { - assert.equal( - handlerForConnection({}, "GET", "/the/websocket"), - fallback404Handler, - ); - }); - - await t.test("the declared handler when it exists", () => { - const fn1 = () => {}; - assert.equal( - handlerForConnection({ - websocket: { - GET: { - known: { - path: { - "": fn1, - }, - }, - }, - }, - }, "GET", "/known/path"), - fn1, - ); - }); -}; - -const test_makeUpgradeListener = async t => { - t.start("makeUpgradeListener()"); - - await t.test("straightforward connection stablishing", async () => { - const calls = []; - const fn = (_req, socket) => calls.push(socket); - const routes = [[ "WEBSOCKET", "/sock", fn ]]; - const table = buildRoutes(routes); - const upgradeListener = makeUpgradeListener(table); - - const req = { - method: "GET", - url: "/sock", - }; - const socket = "the socket" - await upgradeListener(req, socket); - assert.deepEqual(calls, ["the socket"]); - }); - - await t.test("early termination cases", async () => { - const calls = []; - const fn = (req, socket) => calls.push(socket); - const routes = [[ "WEBSOCKET", "/another", fn ]]; - const table = buildRoutes(routes); - const upgradeListener = makeUpgradeListener(table); - - const req405 = { - method: "PUT", - url: "/unused", - }; - let destroyed405 = false - const socket405 = { - end: s => { - assert.equal(s, buildHttpPayload(405)); - return socket405; - }, - destroySoon: () => destroyed405 = true, - }; - await upgradeListener(req405, socket405); - assert.ok(destroyed405); - - const req404 = { - method: "GET", - url: "/bad/path", - }; - let destroyed404 = false; - const socket404 = { - end: s => { - assert.equal(s, buildHttpPayload(404)); - return socket404; - }, - destroySoon: () => destroyed404 = true, - }; - await upgradeListener(req404, socket404); - assert.ok(destroyed404); - }); -}; - const test_makeRequestListener = async t => { t.start("makeRequestListener()"); @@ -2316,10 +2148,6 @@ await runner.runTests([ test_extractQueryParams, test_make404Handler, test_handleRequest, - test_emitHeaders, - test_buildHttpPayload, - test_handlerForConnection, - test_makeUpgradeListener, test_makeRequestListener, test_actionsFn, test_lineHandlerFn, |