From 8ab4b7b7ccd0d48903b4b2aaa64ce6f53d3602c1 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 19 Dec 2023 13:37:49 +0100 Subject: [PATCH] Add unit tests for hasProtocol --- .../src/rpcclients/rpcclient.spec.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/tendermint-rpc/src/rpcclients/rpcclient.spec.ts b/packages/tendermint-rpc/src/rpcclients/rpcclient.spec.ts index a5fb0310bd..9097dec2c1 100644 --- a/packages/tendermint-rpc/src/rpcclients/rpcclient.spec.ts +++ b/packages/tendermint-rpc/src/rpcclients/rpcclient.spec.ts @@ -41,3 +41,30 @@ describe("RpcClient", () => { wsClient.disconnect(); }); }); + +describe("hasProtocol", () => { + it("works", () => { + expect(hasProtocol("https://my.rpc.net")).toEqual(true); + expect(hasProtocol("https://my.rpc.net:443")).toEqual(true); + expect(hasProtocol("https://my.rpc.net:443/somewhere")).toEqual(true); + expect(hasProtocol("http://my.rpc.net")).toEqual(true); + expect(hasProtocol("http://my.rpc.net:443")).toEqual(true); + expect(hasProtocol("http://my.rpc.net:443/somewhere")).toEqual(true); + expect(hasProtocol("wss://my.rpc.net")).toEqual(true); + expect(hasProtocol("wss://my.rpc.net:443")).toEqual(true); + expect(hasProtocol("wss://my.rpc.net:443/somewhere")).toEqual(true); + expect(hasProtocol("ws://my.rpc.net")).toEqual(true); + expect(hasProtocol("ws://my.rpc.net:443")).toEqual(true); + expect(hasProtocol("ws://my.rpc.net:443/somewhere")).toEqual(true); + expect(hasProtocol("ws://my.rpc.net:443/somewhere")).toEqual(true); + expect(hasProtocol("file:///Users/joe/Library/CloudStorage/Notes.pdf")).toEqual(true); + + // Protocols without double slash is not what we want to see here + expect(hasProtocol("tel:+1-201-555-0123")).toEqual(false); + + // No protocols + expect(hasProtocol("")).toEqual(false); + expect(hasProtocol(" ")).toEqual(false); + expect(hasProtocol("/")).toEqual(false); + }); +});