Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/config/src/routing.branches.test.ts
T

42 lines
1.7 KiB
TypeScript

import { describe, expect, test } from "vitest";
import { getDomainRoutingConfig, hostMatches } from "./routing.js";
describe("getDomainRoutingConfig non-local subdomain derivation", () => {
test("preserves an explicit port when deriving canonical subdomains", () => {
expect(getDomainRoutingConfig({ APP_BASE_DOMAIN: "example.com:8443" })).toMatchObject({
appBaseDomain: "example.com:8443",
webAppHost: "app.example.com:8443",
adminAppHost: "admin.example.com:8443",
apiHost: "api.example.com:8443",
portalAppHost: "portal.example.com:8443",
protocol: "https",
});
});
});
describe("hostMatches edge cases", () => {
test("returns false when either host normalizes to nothing", () => {
expect(hostMatches(undefined, "app.example.com")).toBe(false);
expect(hostMatches("app.example.com", " ")).toBe(false);
expect(hostMatches(undefined, undefined)).toBe(false);
});
test("treats local hosts as matching when only one carries a dev port", () => {
expect(hostMatches("app.localhost:3000", "app.localhost")).toBe(true);
expect(hostMatches("app.localhost", "app.localhost:3000")).toBe(true);
});
test("rejects two local hosts that both pin different dev ports", () => {
expect(hostMatches("app.localhost:3000", "app.localhost:4000")).toBe(false);
});
test("rejects local hosts with different hostnames even without ports", () => {
expect(hostMatches("app.localhost", "api.localhost")).toBe(false);
});
test("rejects non-equal hosts that are not both local", () => {
expect(hostMatches("app.example.com", "app.example.org")).toBe(false);
expect(hostMatches("app.localhost:3000", "app.example.com:3000")).toBe(false);
});
});