import { describe, expect, test } from "vitest"; import { getDomainRoutingConfig, hostMatches, normalizeHost } from "./routing.js"; describe("routing config", () => { test("uses local subdomain defaults", () => { expect(getDomainRoutingConfig({})).toEqual({ appBaseDomain: "localhost", webAppHost: "app.localhost", adminAppHost: "admin.localhost", apiHost: "api.localhost", protocol: "http", }); }); test("preserves local dev ports on derived hosts", () => { expect(getDomainRoutingConfig({ APP_BASE_DOMAIN: "localhost:3000" })).toMatchObject({ webAppHost: "app.localhost:3000", adminAppHost: "admin.localhost:3000", apiHost: "api.localhost:3000", }); }); test("normalizes explicit hosts", () => { expect(normalizeHost("https://APP.example.com/path")).toBe("app.example.com"); expect(hostMatches("https://app.example.com", "app.example.com")).toBe(true); }); test("uses explicit app, admin, api, base domain, and protocol hosts", () => { expect( getDomainRoutingConfig({ APP_BASE_DOMAIN: "Example.com", WEB_APP_HOST: "https://APP.example.com/ignored/path", ADMIN_APP_HOST: "ADMIN.example.com:8443", API_HOST: "https://API.example.com/v1", APP_PROTOCOL: "http", }) ).toEqual({ appBaseDomain: "example.com", webAppHost: "app.example.com", adminAppHost: "admin.example.com:8443", apiHost: "api.example.com", protocol: "http", }); }); test("derives canonical subdomains and https for non-local base domains", () => { expect(getDomainRoutingConfig({ APP_BASE_DOMAIN: "example.com" })).toMatchObject({ appBaseDomain: "example.com", webAppHost: "app.example.com", adminAppHost: "admin.example.com", apiHost: "api.example.com", protocol: "https", }); }); });