import { describe, expect, it, beforeEach, afterEach } from "vitest";
import { getEnv } from "../env.js";
describe("getEnv", () => {
    let originalGatewayUrl;
    beforeEach(() => {
        originalGatewayUrl = process.env.GATEWAY_URL;
    });
    afterEach(() => {
        if (originalGatewayUrl === undefined) {
            delete process.env.GATEWAY_URL;
        }
        else {
            process.env.GATEWAY_URL = originalGatewayUrl;
        }
    });
    it("should return gatewayUrl from GATEWAY_URL env var", () => {
        process.env.GATEWAY_URL = "wss://custom-gateway.example.com";
        const env = getEnv();
        expect(env.gatewayUrl).toBe("wss://custom-gateway.example.com");
    });
    it("should default to wss://pocketcoder-gateway.fly.dev if not set", () => {
        delete process.env.GATEWAY_URL;
        const env = getEnv();
        expect(env.gatewayUrl).toBe("wss://pocketcoder-gateway.fly.dev");
    });
    it("should accept ws:// URLs for local development", () => {
        process.env.GATEWAY_URL = "ws://localhost:8080";
        const env = getEnv();
        expect(env.gatewayUrl).toBe("ws://localhost:8080");
    });
    it("should throw for invalid URL (not ws:// or wss://)", () => {
        process.env.GATEWAY_URL = "https://gateway.pocketcoder.dev";
        expect(() => getEnv()).toThrow('Invalid GATEWAY_URL: "https://gateway.pocketcoder.dev". Must start with ws:// or wss://');
    });
    it("should throw for http URL", () => {
        process.env.GATEWAY_URL = "http://localhost:8080";
        expect(() => getEnv()).toThrow("Must start with ws:// or wss://");
    });
    it("should throw for empty string", () => {
        process.env.GATEWAY_URL = "";
        expect(() => getEnv()).toThrow("Must start with ws:// or wss://");
    });
});
//# sourceMappingURL=env.test.js.map