feat: update projects API to include display names
- 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>
This commit is contained in:
41
app/api/__tests__/projects.test.ts
Normal file
41
app/api/__tests__/projects.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user