full upgrade to dev

This commit is contained in:
2026-01-08 11:31:57 +01:00
parent 4bf94007cc
commit 7320a0562d
17 changed files with 629 additions and 442 deletions

View File

@@ -1,12 +1,10 @@
import '@testing-library/jest-dom';
import { GET } from '@/app/sitemap.xml/route';
import { mockFetch } from '@/app/__tests__/__mocks__/mock-fetch-sitemap';
import "@testing-library/jest-dom";
import { GET } from "@/app/sitemap.xml/route";
jest.mock('next/server', () => ({
jest.mock("next/server", () => ({
NextResponse: jest.fn().mockImplementation(function (body, init) {
// eslint-disable-next-line no-invalid-this
this.body = body;
// eslint-disable-next-line no-invalid-this
this.init = init;
}),
}));
@@ -33,36 +31,49 @@ const sitemapXml = `
`;
// Mock node-fetch for sitemap endpoint (hoisted by Jest)
jest.mock('node-fetch', () => ({
jest.mock("node-fetch", () => ({
__esModule: true,
default: jest.fn((url: string) => Promise.resolve({ ok: true, text: () => Promise.resolve(sitemapXml) })),
default: jest.fn((_url: string) =>
Promise.resolve({ ok: true, text: () => Promise.resolve(sitemapXml) }),
),
}));
describe('Sitemap Component', () => {
describe("Sitemap Component", () => {
beforeAll(() => {
process.env.NEXT_PUBLIC_BASE_URL = 'https://dki.one';
process.env.NEXT_PUBLIC_BASE_URL = "https://dki.one";
// Provide sitemap XML directly so route uses it without fetching
process.env.GHOST_MOCK_SITEMAP = sitemapXml;
// Mock global.fetch too, to avoid any network calls
global.fetch = jest.fn().mockImplementation((url: string) => {
if (url.includes('/api/sitemap')) {
return Promise.resolve({ ok: true, text: () => Promise.resolve(sitemapXml) });
if (url.includes("/api/sitemap")) {
return Promise.resolve({
ok: true,
text: () => Promise.resolve(sitemapXml),
});
}
return Promise.reject(new Error(`Unknown URL: ${url}`));
});
});
it('should render the sitemap XML', async () => {
it("should render the sitemap XML", async () => {
const response = await GET();
expect(response.body).toContain('<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">');
expect(response.body).toContain('<loc>https://dki.one/</loc>');
expect(response.body).toContain('<loc>https://dki.one/legal-notice</loc>');
expect(response.body).toContain('<loc>https://dki.one/privacy-policy</loc>');
expect(response.body).toContain('<loc>https://dki.one/projects/just-doing-some-testing</loc>');
expect(response.body).toContain('<loc>https://dki.one/projects/blockchain-based-voting-system</loc>');
expect(response.body).toContain(
'<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">',
);
expect(response.body).toContain("<loc>https://dki.one/</loc>");
expect(response.body).toContain("<loc>https://dki.one/legal-notice</loc>");
expect(response.body).toContain(
"<loc>https://dki.one/privacy-policy</loc>",
);
expect(response.body).toContain(
"<loc>https://dki.one/projects/just-doing-some-testing</loc>",
);
expect(response.body).toContain(
"<loc>https://dki.one/projects/blockchain-based-voting-system</loc>",
);
// Note: Headers are not available in test environment
});
});
});