feat: implement dark mode infrastructure, optimize images, and add SEO structured data
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 10m16s
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 10m16s
This commit is contained in:
69
app/__tests__/api/book-reviews.test.tsx
Normal file
69
app/__tests__/api/book-reviews.test.tsx
Normal file
@@ -0,0 +1,69 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GET } from '@/app/api/book-reviews/route';
|
||||
import { getBookReviews } from '@/lib/directus';
|
||||
|
||||
jest.mock('@/lib/directus', () => ({
|
||||
getBookReviews: 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/book-reviews', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return book reviews from Directus', async () => {
|
||||
const mockReviews = [
|
||||
{
|
||||
id: '1',
|
||||
book_title: 'Test Book',
|
||||
book_author: 'Test Author',
|
||||
rating: 5,
|
||||
review: 'Great book!',
|
||||
},
|
||||
];
|
||||
|
||||
(getBookReviews as jest.Mock).mockResolvedValue(mockReviews);
|
||||
|
||||
const request = {
|
||||
url: 'http://localhost/api/book-reviews?locale=en',
|
||||
} as any;
|
||||
|
||||
await GET(request);
|
||||
|
||||
expect(NextResponse.json).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
bookReviews: mockReviews,
|
||||
source: 'directus',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should return fallback when no reviews found', async () => {
|
||||
(getBookReviews as jest.Mock).mockResolvedValue(null);
|
||||
|
||||
const request = {
|
||||
url: 'http://localhost/api/book-reviews?locale=en',
|
||||
} as any;
|
||||
|
||||
await GET(request);
|
||||
|
||||
expect(NextResponse.json).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
bookReviews: null,
|
||||
source: 'fallback',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user