60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { isAdminSurface, isAppOrAdminSurface, isAppSurface } from "./HostAwareSurface";
|
|
|
|
const routing = {
|
|
appBaseDomain: "example.test",
|
|
webAppHost: "app.example.test",
|
|
adminAppHost: "admin.example.test",
|
|
apiHost: "api.example.test",
|
|
protocol: "https",
|
|
} as const;
|
|
|
|
describe("HostAwareSurface", () => {
|
|
test("classifies canonical app and admin hosts by request origin", () => {
|
|
expect(
|
|
isAppSurface(
|
|
{
|
|
serverUrl: "https://app.example.test",
|
|
publicBaseUrl: "https://example.test",
|
|
routing,
|
|
},
|
|
"/acme/dashboard"
|
|
)
|
|
).toBe(true);
|
|
|
|
expect(
|
|
isAdminSurface(
|
|
{
|
|
serverUrl: "https://admin.example.test",
|
|
publicBaseUrl: "https://example.test",
|
|
routing,
|
|
},
|
|
"/dashboard"
|
|
)
|
|
).toBe(true);
|
|
});
|
|
|
|
test("keeps public routes on the web app host out of app chrome", () => {
|
|
const input = {
|
|
serverUrl: "https://app.example.test",
|
|
publicBaseUrl: "https://example.test",
|
|
routing,
|
|
};
|
|
|
|
expect(isAppSurface(input, "/docs/getting-started")).toBe(false);
|
|
expect(isAppOrAdminSurface(input, "/docs/getting-started")).toBe(false);
|
|
expect(isAppSurface(input, "/acme/dashboard")).toBe(true);
|
|
});
|
|
|
|
test("keeps admin host settings classified as admin chrome", () => {
|
|
const input = {
|
|
serverUrl: "https://admin.example.test",
|
|
publicBaseUrl: "https://example.test",
|
|
routing,
|
|
};
|
|
|
|
expect(isAdminSurface(input, "/settings/profile")).toBe(true);
|
|
expect(isAppOrAdminSurface(input, "/settings/profile")).toBe(true);
|
|
});
|
|
});
|