Files
portfolio/app/__tests__/api/fetchProject.test.tsx

48 lines
1.5 KiB
TypeScript

import { GET } from '@/app/api/fetchProject/route';
import { NextRequest, NextResponse } from 'next/server';
import { mockFetch } from '@/app/__tests__/__mocks__/mock-fetch';
jest.mock('next/server', () => ({
NextResponse: {
json: jest.fn(),
},
}));
describe('GET /api/fetchProject', () => {
beforeAll(() => {
process.env.GHOST_API_URL = 'http://localhost:2368';
process.env.GHOST_API_KEY = 'some-key';
global.fetch = mockFetch({
posts: [
{
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 fetch a project by slug', async () => {
const mockRequest = {
url: 'http://localhost/api/fetchProject?slug=blockchain-based-voting-system',
} as unknown as NextRequest;
await GET(mockRequest);
expect(NextResponse.json).toHaveBeenCalledWith({
posts: [
{
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',
},
],
});
});
});