- Modified projects API route to return objects with name and displayName fields - Added comprehensive tests for the updated API response structure - Tests verify display name mapping and error handling - All existing tests continue to pass Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
/**
|
|
* @jest-environment node
|
|
*/
|
|
|
|
import { GET } from '../projects/route';
|
|
import { getProjects } from '@/lib/fs-utils';
|
|
|
|
jest.mock('@/lib/fs-utils');
|
|
jest.mock('@/lib/utils', () => ({
|
|
getProjectDisplayName: jest.fn((name) => name === 'FT' ? '外放构建' : name),
|
|
}));
|
|
|
|
describe('/api/projects', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should return projects with display names', async () => {
|
|
(getProjects as jest.Mock).mockResolvedValue(['FT', 'FT_DEV', 'UNKNOWN']);
|
|
|
|
const response = await GET();
|
|
const data = await response.json();
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(data).toEqual([
|
|
{ name: 'FT', displayName: '外放构建' },
|
|
{ name: 'FT_DEV', displayName: 'FT_DEV' },
|
|
{ name: 'UNKNOWN', displayName: 'UNKNOWN' },
|
|
]);
|
|
});
|
|
|
|
it('should handle errors gracefully', async () => {
|
|
(getProjects as jest.Mock).mockRejectedValue(new Error('File system error'));
|
|
|
|
const response = await GET();
|
|
const data = await response.json();
|
|
|
|
expect(response.status).toBe(500);
|
|
expect(data.error).toBe('Failed to fetch projects');
|
|
});
|
|
});
|