55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const getHostRoutingContextFromRequest = vi.fn();
|
|
|
|
vi.mock("~/utils/app/HostRouting.server", () => ({
|
|
getHostRoutingContextFromRequest: (request: Request) => getHostRoutingContextFromRequest(request),
|
|
}));
|
|
|
|
vi.mock("~/services/mcp/oauth.server", () => ({
|
|
oauthAuthorizationServerMetadata: () => ({ issuer: "https://example.test" }),
|
|
}));
|
|
|
|
async function loadCatchAll(url: string) {
|
|
const { loader } = await import("./$");
|
|
return loader({ request: new Request(url), params: {}, context: {} } as LoaderFunctionArgs);
|
|
}
|
|
|
|
describe("catch-all 404 surface", () => {
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
getHostRoutingContextFromRequest.mockReset();
|
|
});
|
|
|
|
it("marks unknown admin-host paths as the operator surface", async () => {
|
|
// Regression guard: `/sales/today` rendered the marketing 404 with
|
|
// "Anmelden"/"Registrieren"/AGB footer links on the admin host.
|
|
getHostRoutingContextFromRequest.mockReturnValue("admin");
|
|
|
|
const response = (await loadCatchAll("https://staging-admin.hivegrid.de/sales/today")) as Response;
|
|
|
|
expect(response.status).toBe(404);
|
|
await expect(response.json()).resolves.toEqual({ surface: "admin" });
|
|
});
|
|
|
|
it("keeps the public surface for every other host", async () => {
|
|
getHostRoutingContextFromRequest.mockReturnValue("app");
|
|
|
|
const response = (await loadCatchAll("https://app.hivegrid.de/does-not-exist")) as Response;
|
|
|
|
expect(response.status).toBe(404);
|
|
await expect(response.json()).resolves.toEqual({ surface: "public" });
|
|
});
|
|
|
|
it("still serves the OAuth authorization-server metadata", async () => {
|
|
getHostRoutingContextFromRequest.mockReturnValue("admin");
|
|
|
|
const response = (await loadCatchAll("https://staging-admin.hivegrid.de/.well-known/oauth-authorization-server")) as Response;
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.headers.get("Cache-Control")).toBe("no-store");
|
|
await expect(response.json()).resolves.toEqual({ issuer: "https://example.test" });
|
|
});
|
|
});
|