123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import { wsValid, httpValid, socketioValid } from "../valid"
- describe("wsValid", () => {
- test("returns true for valid URL with IP address", () => {
- expect(wsValid("wss://174.129.224.73/")).toBe(true)
- expect(wsValid("wss://174.129.224.73")).toBe(true)
- })
- test("returns true for valid URL with Hostname", () => {
- expect(wsValid("wss://hoppscotch-websocket.herokuapp.com/")).toBe(true)
- expect(wsValid("wss://hoppscotch-websocket.herokuapp.com")).toBe(true)
- })
- test("returns false for invalid URL with IP address", () => {
- expect(wsValid("wss://174.129.")).toBe(false)
- expect(wsValid("wss://174.129./")).toBe(false)
- })
- test("returns false for invalid URL with hostname", () => {
- expect(wsValid("wss://echo.websocket./")).toBe(false)
- expect(wsValid("wss://echo.websocket.")).toBe(false)
- })
- test("returns false for non-wss protocol URLs", () => {
- expect(wsValid("http://echo.websocket.org/")).toBe(false)
- expect(wsValid("http://echo.websocket.org")).toBe(false)
- expect(wsValid("http://174.129.224.73/")).toBe(false)
- expect(wsValid("http://174.129.224.73")).toBe(false)
- })
- test("returns true for wss protocol URLs", () => {
- expect(wsValid("wss://hoppscotch-websocket.herokuapp.com/")).toBe(true)
- expect(wsValid("wss://hoppscotch-websocket.herokuapp.com")).toBe(true)
- expect(wsValid("wss://174.129.224.73/")).toBe(true)
- expect(wsValid("wss://174.129.224.73")).toBe(true)
- })
- test("returns true for ws protocol URLs", () => {
- expect(wsValid("ws://echo.websocket.org/")).toBe(true)
- expect(wsValid("ws://echo.websocket.org")).toBe(true)
- expect(wsValid("ws://174.129.224.73/")).toBe(true)
- expect(wsValid("ws://174.129.224.73")).toBe(true)
- })
- })
- describe("httpValid", () => {
- test("returns true for valid URL with IP address", () => {
- expect(httpValid("http://174.129.224.73/")).toBe(true)
- expect(httpValid("http://174.129.224.73")).toBe(true)
- })
- test("returns true for valid URL with Hostname", () => {
- expect(httpValid("http://echo.websocket.org/")).toBe(true)
- expect(httpValid("http://echo.websocket.org")).toBe(true)
- })
- test("returns false for invalid URL with IP address", () => {
- expect(httpValid("http://174.129./")).toBe(false)
- expect(httpValid("http://174.129.")).toBe(false)
- })
- test("returns false for invalid URL with hostname", () => {
- expect(httpValid("http://echo.websocket./")).toBe(false)
- expect(httpValid("http://echo.websocket.")).toBe(false)
- })
- test("returns false for non-http(s) protocol URLs", () => {
- expect(httpValid("wss://hoppscotch-websocket.herokuapp.com/")).toBe(false)
- expect(httpValid("wss://hoppscotch-websocket.herokuapp.com")).toBe(false)
- expect(httpValid("wss://174.129.224.73/")).toBe(false)
- expect(httpValid("wss://174.129.224.73")).toBe(false)
- })
- test("returns true for HTTP protocol URLs", () => {
- expect(httpValid("http://echo.websocket.org/")).toBe(true)
- expect(httpValid("http://echo.websocket.org")).toBe(true)
- expect(httpValid("http://174.129.224.73/")).toBe(true)
- expect(httpValid("http://174.129.224.73")).toBe(true)
- })
- test("returns true for HTTPS protocol URLs", () => {
- expect(httpValid("https://echo.websocket.org/")).toBe(true)
- expect(httpValid("https://echo.websocket.org")).toBe(true)
- expect(httpValid("https://174.129.224.73/")).toBe(true)
- expect(httpValid("https://174.129.224.73")).toBe(true)
- })
- })
- describe("socketioValid", () => {
- test("returns true for valid URL with IP address", () => {
- expect(socketioValid("http://174.129.224.73/")).toBe(true)
- expect(socketioValid("http://174.129.224.73")).toBe(true)
- })
- test("returns true for valid URL with Hostname", () => {
- expect(socketioValid("http://echo.websocket.org/")).toBe(true)
- expect(socketioValid("http://echo.websocket.org")).toBe(true)
- })
- test("returns false for invalid URL with IP address", () => {
- expect(socketioValid("http://174.129./")).toBe(false)
- expect(socketioValid("http://174.129.")).toBe(false)
- })
- test("returns false for invalid URL with hostname", () => {
- expect(socketioValid("http://echo.websocket./")).toBe(false)
- expect(socketioValid("http://echo.websocket.")).toBe(false)
- })
- test("returns false for non-http(s) and non-wss protocol URLs", () => {
- expect(socketioValid("ftp://echo.websocket.org/")).toBe(false)
- expect(socketioValid("ftp://echo.websocket.org")).toBe(false)
- expect(socketioValid("ftp://174.129.224.73/")).toBe(false)
- expect(socketioValid("ftp://174.129.224.73")).toBe(false)
- })
- test("returns true for HTTP protocol URLs", () => {
- expect(socketioValid("http://echo.websocket.org/")).toBe(true)
- expect(socketioValid("http://echo.websocket.org")).toBe(true)
- expect(socketioValid("http://174.129.224.73/")).toBe(true)
- expect(socketioValid("http://174.129.224.73")).toBe(true)
- })
- test("returns true for HTTPS protocol URLs", () => {
- expect(socketioValid("https://echo.websocket.org/")).toBe(true)
- expect(socketioValid("https://echo.websocket.org")).toBe(true)
- expect(socketioValid("https://174.129.224.73/")).toBe(true)
- expect(socketioValid("https://174.129.224.73")).toBe(true)
- })
- test("returns true for wss protocol URLs", () => {
- expect(socketioValid("wss://hoppscotch-websocket.herokuapp.com/")).toBe(
- true
- )
- expect(socketioValid("wss://hoppscotch-websocket.herokuapp.com")).toBe(true)
- expect(socketioValid("wss://174.129.224.73/")).toBe(true)
- expect(socketioValid("wss://174.129.224.73")).toBe(true)
- })
- test("returns true for ws protocol URLs", () => {
- expect(socketioValid("ws://echo.websocket.org/")).toBe(true)
- expect(socketioValid("ws://echo.websocket.org")).toBe(true)
- expect(socketioValid("ws://174.129.224.73/")).toBe(true)
- expect(socketioValid("ws://174.129.224.73")).toBe(true)
- })
- })
|