diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/js/hero.mjs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index f964a88..436535a 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -33,6 +33,9 @@ import { handleRequest, emitHeaders, buildHttpPayload, + fallback404Handler, + fallback405Handler, + handlerForConnection, makeRequestListener, actionsFn, lineHandlerFn, @@ -1217,6 +1220,42 @@ const test_buildHttpPayload = async t => { }); }; +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_makeRequestListener = async t => { t.start("makeRequestListener()"); @@ -1911,6 +1950,7 @@ await runner.runTests([ test_handleRequest, test_emitHeaders, test_buildHttpPayload, + test_handlerForConnection, test_makeRequestListener, test_actionsFn, test_lineHandlerFn, |