Files
Termix/plugins/remote-desktop/tests/frontend/guacamole-websocket-url.test.ts
T

61 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-06-29 13:28:26 -05:00
import { describe, expect, it } from "vitest";
2026-10-01 16:20:16 -05:00
import { buildGuacamoleWebSocketBaseUrl } from "../../src/frontend/guacamole-websocket-url.js";
2026-06-29 13:28:26 -05:00
const httpsLocation = {
protocol: "https:",
host: "termix.example.com",
} as Location;
2026-10-01 16:20:16 -05:00
// The display socket moved off port 30008 to /plugin-ws/remote-desktop/display
// on the main backend, so every case below asserts the same one path. Dev is
// no longer a special case: Vite proxies the backend, so there is nothing to
// point at a separate port.
const ROUTE = "/plugin-ws/remote-desktop/display";
2026-06-29 13:28:26 -05:00
describe("buildGuacamoleWebSocketBaseUrl", () => {
2026-10-01 16:20:16 -05:00
it("uses the same origin in production web builds", () => {
2026-06-29 13:28:26 -05:00
expect(
buildGuacamoleWebSocketBaseUrl({
isElectronApp: false,
isEmbeddedApp: false,
basePath: "",
location: httpsLocation,
}),
2026-10-01 16:20:16 -05:00
).toBe(`wss://termix.example.com${ROUTE}`);
2026-06-29 13:28:26 -05:00
});
it("preserves the runtime base path for proxied web deployments", () => {
expect(
buildGuacamoleWebSocketBaseUrl({
isElectronApp: false,
isEmbeddedApp: false,
basePath: "/termix",
location: httpsLocation,
}),
2026-10-01 16:20:16 -05:00
).toBe(`wss://termix.example.com/termix${ROUTE}`);
2026-06-29 13:28:26 -05:00
});
2026-10-01 16:20:16 -05:00
it("targets the embedded backend for electron running locally", () => {
2026-06-29 13:28:26 -05:00
expect(
buildGuacamoleWebSocketBaseUrl({
isElectronApp: true,
isEmbeddedApp: true,
basePath: "/termix",
location: httpsLocation,
}),
2026-10-01 16:20:16 -05:00
).toBe(`ws://127.0.0.1:30001${ROUTE}`);
2026-06-29 13:28:26 -05:00
});
it("uses the configured remote server URL for electron remote mode", () => {
expect(
buildGuacamoleWebSocketBaseUrl({
isElectronApp: true,
isEmbeddedApp: false,
configuredServerUrl: "https://termix.example.com/termix/",
basePath: "",
location: httpsLocation,
}),
2026-10-01 16:20:16 -05:00
).toBe(`wss://termix.example.com/termix${ROUTE}`);
2026-06-29 13:28:26 -05:00
});
});