diff --git a/server/response_test.ts b/server/response_test.ts index 1b7ff02..910df72 100644 --- a/server/response_test.ts +++ b/server/response_test.ts @@ -255,6 +255,8 @@ Deno.test("rpc call with a custom error", async function (): Promise< Deno.test("rpc call with jwt", async function (): Promise { const sentToServer = '{"jsonrpc": "2.0", "method": "login", "id": 3}'; const sentToClient = '{"jsonrpc": "2.0", "result": "Bob", "id": 3}'; + const authorizationError = + '{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}'; const reqOne = createReq(sentToServer); reqOne.headers.append("Authorization", `Bearer ${jwt}`); assertEquals( @@ -273,7 +275,7 @@ Deno.test("rpc call with jwt", async function (): Promise { reqTwo, )).text(), removeWhiteSpace( - '{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}', + authorizationError, ), ); const reqThree = createReq( @@ -286,7 +288,7 @@ Deno.test("rpc call with jwt", async function (): Promise { methods: new RegExp(".+"), })(reqThree)).text(), removeWhiteSpace( - '{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}', + authorizationError, ), ); const reqFour = createReq( @@ -311,7 +313,7 @@ Deno.test("rpc call with jwt", async function (): Promise { methods: ["login"], })(reqFive)).text(), removeWhiteSpace( - '{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}', + authorizationError, ), ); const reqSix = createReq(sentToServer); @@ -337,9 +339,7 @@ Deno.test("rpc call with jwt", async function (): Promise { }])( reqSeven, )).text(), - removeWhiteSpace( - '{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}', - ), + removeWhiteSpace(authorizationError), ); const reqEight = createReq(sentToServer); reqEight.headers.append("Authorization", `Bearer ${jwt}`), @@ -355,4 +355,21 @@ Deno.test("rpc call with jwt", async function (): Promise { )).text(), removeWhiteSpace(sentToClient), ); + const reqNine = createReq(sentToServer); + reqNine.headers.append("Authorization", `Bearer ${jwt}`), + assertEquals( + await (await respond(methods, {}, [{ + methods: ["login"], + verification: cryptoKey, + }, { + methods: ["login"], + verification: cryptoKey, + options: { + predicates: [() => false], + }, + }])( + reqNine, + )).text(), + removeWhiteSpace(authorizationError), + ); });