import { NextRequest, NextResponse } from 'next/server'; jest.mock('@/lib/prisma', () => ({ prisma: { project: { findUnique: jest.fn(async ({ where }: { where: { slug: string } }) => { if (where.slug !== 'blockchain-based-voting-system') return null; return { id: 2, title: 'Blockchain Based Voting System', metaDescription: 'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.', slug: 'blockchain-based-voting-system', updatedAt: new Date('2025-02-13T16:54:42.000Z'), description: null, content: null, }; }), }, }, })); jest.mock('next/server', () => ({ NextResponse: { json: jest.fn(), }, })); describe('GET /api/fetchProject', () => { it('should fetch a project by slug', async () => { const { GET } = await import('@/app/api/fetchProject/route'); 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: '2', 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.000Z', }, ], }); }); });