Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

endpoint.test.ts

61 lines1.8 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 classifyHostedHttpsCompatibility,
5 createAdvertisedEndpoint,
6 deriveWsBaseUrl,
7 normalizeHttpBaseUrl,
8} from "./endpoint.ts";
9​
10const coreProvider = {
11 id: "desktop-core",
12 label: "Desktop",
13 kind: "core",
14 isAddon: false,
15} as const;
16​
17describe("advertised endpoint helpers", () => {
18 it("normalizes HTTP and WebSocket base URLs", () => {
19 expect(normalizeHttpBaseUrl("https://example.com/path?x=1#hash")).toBe("https://example.com/");
20 expect(normalizeHttpBaseUrl("wss://example.com/socket")).toBe("https://example.com/");
21 expect(deriveWsBaseUrl("https://example.com/api")).toBe("wss://example.com/");
22 expect(deriveWsBaseUrl("http://127.0.0.1:3773")).toBe("ws://127.0.0.1:3773/");
23 });
24​
25 it("marks HTTP endpoints as blocked from hosted HTTPS apps", () => {
26 expect(classifyHostedHttpsCompatibility("http://192.168.1.44:3773")).toBe(
27 "mixed-content-blocked",
28 );
29 expect(classifyHostedHttpsCompatibility("https://desktop.example.com", "compatible")).toBe(
30 "compatible",
31 );
32 });
33​
34 it("creates provider-neutral endpoint records", () => {
35 expect(
36 createAdvertisedEndpoint({
37 id: "lan:http://192.168.1.44:3773",
38 label: "LAN",
39 provider: coreProvider,
40 httpBaseUrl: "http://192.168.1.44:3773",
41 reachability: "lan",
42 source: "desktop-core",
43 isDefault: true,
44 }),
45 ).toEqual({
46 id: "lan:http://192.168.1.44:3773",
47 label: "LAN",
48 provider: coreProvider,
49 httpBaseUrl: "http://192.168.1.44:3773/",
50 wsBaseUrl: "ws://192.168.1.44:3773/",
51 reachability: "lan",
52 compatibility: {
53 hostedHttpsApp: "mixed-content-blocked",
54 desktopApp: "compatible",
55 },
56 source: "desktop-core",
57 status: "available",
58 isDefault: true,
59 });
60 });
61});