This commit is contained in:
@@ -39,6 +39,8 @@ function createMockRequest(url: string) {
|
||||
describe("middleware locale runtime config", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
process.env.NODE_ENV = "production";
|
||||
delete process.env.SITE_RUNTIME_ORIGIN;
|
||||
createMiddlewareMock.mockReset();
|
||||
intlHandlerMock.mockReset();
|
||||
intlHandlerMock.mockReturnValue(NextResponse.next());
|
||||
@@ -66,6 +68,10 @@ describe("middleware locale runtime config", () => {
|
||||
|
||||
await middleware(request as never);
|
||||
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
new URL("http://127.0.0.1:3000/api/site/default-locale"),
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(createMiddlewareMock).toHaveBeenCalledTimes(1);
|
||||
expect(createMiddlewareMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@@ -115,4 +121,29 @@ describe("middleware locale runtime config", () => {
|
||||
expect(response.headers.get("location")).toBe("https://example.com/coming-soon");
|
||||
expect(intlHandlerMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("prefers the configured internal runtime origin when provided", async () => {
|
||||
process.env.SITE_RUNTIME_ORIGIN = "http://app:3000";
|
||||
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
defaultLocale: "en",
|
||||
maintenanceEnabled: false,
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
||||
const { default: middleware } = await import("../middleware");
|
||||
const request = createMockRequest("https://example.com/");
|
||||
|
||||
await middleware(request as never);
|
||||
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
new URL("http://app:3000/api/site/default-locale"),
|
||||
expect.any(Object),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user