Files
portfolio/app/__tests__/api/tech-stack.test.tsx
denshooter 0766b46cc8
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 10m16s
feat: implement dark mode infrastructure, optimize images, and add SEO structured data
2026-02-15 22:20:49 +01:00

72 lines
1.5 KiB
TypeScript

import { NextResponse } from 'next/server';
import { GET } from '@/app/api/tech-stack/route';
import { getTechStack } from '@/lib/directus';
jest.mock('@/lib/directus', () => ({
getTechStack: jest.fn(),
}));
jest.mock('next/server', () => ({
NextRequest: jest.fn((url) => ({
url,
})),
NextResponse: {
json: jest.fn((data, options) => ({
json: async () => data,
status: options?.status || 200,
})),
},
}));
describe('GET /api/tech-stack', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should return tech stack from Directus', async () => {
const mockTechStack = [
{
id: '1',
key: 'frontend',
icon: 'Globe',
name: 'Frontend',
items: [
{ id: '1-1', name: 'React' }
],
},
];
(getTechStack as jest.Mock).mockResolvedValue(mockTechStack);
const request = {
url: 'http://localhost/api/tech-stack?locale=en',
} as any;
await GET(request);
expect(NextResponse.json).toHaveBeenCalledWith(
expect.objectContaining({
techStack: mockTechStack,
source: 'directus',
})
);
});
it('should return fallback when no tech stack found', async () => {
(getTechStack as jest.Mock).mockResolvedValue(null);
const request = {
url: 'http://localhost/api/tech-stack?locale=en',
} as any;
await GET(request);
expect(NextResponse.json).toHaveBeenCalledWith(
expect.objectContaining({
techStack: null,
source: 'fallback',
})
);
});
});