44 lines
1.8 KiB
TypeScript
44 lines
1.8 KiB
TypeScript
import { GET } from '@/app/api/sitemap/route';
|
|
import { mockFetch } from '@/app/__tests__/__mocks__/mock-fetch';
|
|
|
|
jest.mock('next/server', () => ({
|
|
NextResponse: jest.fn().mockImplementation((body, init) => ({ body, init })),
|
|
}));
|
|
|
|
describe('GET /api/sitemap', () => {
|
|
beforeAll(() => {
|
|
process.env.GHOST_API_URL = 'http://localhost:2368';
|
|
process.env.GHOST_API_KEY = 'test-api-key';
|
|
process.env.NEXT_PUBLIC_BASE_URL = 'https://dki.one';
|
|
global.fetch = mockFetch({
|
|
posts: [
|
|
{
|
|
id: '67ac8dfa709c60000117d312',
|
|
title: 'Just Doing Some Testing',
|
|
meta_description: 'Hello bla bla bla bla',
|
|
slug: 'just-doing-some-testing',
|
|
updated_at: '2025-02-13T14:25:38.000+00:00',
|
|
},
|
|
{
|
|
id: '67aaffc3709c60000117d2d9',
|
|
title: 'Blockchain Based Voting System',
|
|
meta_description: 'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.',
|
|
slug: 'blockchain-based-voting-system',
|
|
updated_at: '2025-02-13T16:54:42.000+00:00',
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it('should return a sitemap', 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.init.headers['Content-Type']).toBe('application/xml');
|
|
});
|
|
}); |