jest.mock("next/server", () => { const mockNextResponse = function ( body: string | object, init?: { headers?: Record }, ) { // Return an object that mimics NextResponse const mockResponse = { body, init, text: async () => { if (typeof body === "string") { return body; } else if (body && typeof body === "object") { return JSON.stringify(body); } return ""; }, json: async () => { if (typeof body === "object") { return body; } try { return JSON.parse(body as string); } catch { return {}; } }, }; return mockResponse; }; return { NextResponse: mockNextResponse, }; }); jest.mock("@/lib/sitemap", () => ({ getSitemapEntries: jest.fn(async () => [ { url: "https://dki.one/en", lastModified: "2025-01-01T00:00:00.000Z", }, { url: "https://dki.one/de", lastModified: "2025-01-01T00:00:00.000Z", }, { url: "https://dki.one/en/projects/blockchain-based-voting-system", lastModified: "2025-02-13T16:54:42.000Z", }, { url: "https://dki.one/de/projects/blockchain-based-voting-system", lastModified: "2025-02-13T16:54:42.000Z", }, ]), generateSitemapXml: jest.fn( () => 'https://dki.one/en', ), })); describe("GET /api/sitemap", () => { beforeAll(() => { process.env.NEXT_PUBLIC_BASE_URL = "https://dki.one"; }); it("should return a sitemap", async () => { const { GET } = await import("@/app/api/sitemap/route"); const response = await GET(); // Get the body text from the NextResponse const body = await response.text(); expect(body).toContain( '', ); expect(body).toContain("https://dki.one/en"); // Note: Headers are not available in test environment }); });