missing resume files return safe empty data
This commit is contained in:
parent
e1ee291337
commit
02400df47d
@ -18,6 +18,24 @@ describe.sequential('Profile API routes', () => {
|
||||
await stopServer({ server, closeDb, tempDir });
|
||||
});
|
||||
|
||||
it('returns empty projects when resume is missing', async () => {
|
||||
const res = await fetch(`${baseUrl}/api/profile/projects`);
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.ok).toBe(true);
|
||||
expect(body.success).toBe(true);
|
||||
expect(body.data).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns null profile when resume is missing', async () => {
|
||||
const res = await fetch(`${baseUrl}/api/profile`);
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.ok).toBe(true);
|
||||
expect(body.success).toBe(true);
|
||||
expect(body.data).toBeNull();
|
||||
});
|
||||
|
||||
it('returns base resume projects', async () => {
|
||||
// Create valid resume file first
|
||||
const resumePath = join(tempDir, 'resume.json');
|
||||
|
||||
@ -7,11 +7,24 @@ import { resumeDataSchema } from '@shared/rxresume-schema.js';
|
||||
|
||||
export const profileRouter = Router();
|
||||
|
||||
async function profileExists(): Promise<boolean> {
|
||||
try {
|
||||
const fileInfo = await stat(DEFAULT_PROFILE_PATH);
|
||||
return fileInfo.isFile() && fileInfo.size > 0;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/profile/projects - Get all projects available in the base resume
|
||||
*/
|
||||
profileRouter.get('/projects', async (req: Request, res: Response) => {
|
||||
try {
|
||||
if (!(await profileExists())) {
|
||||
res.json({ success: true, data: [] });
|
||||
return;
|
||||
}
|
||||
const profile = await getProfile();
|
||||
const { catalog } = extractProjectsFromProfile(profile);
|
||||
res.json({ success: true, data: catalog });
|
||||
@ -26,6 +39,10 @@ profileRouter.get('/projects', async (req: Request, res: Response) => {
|
||||
*/
|
||||
profileRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
if (!(await profileExists())) {
|
||||
res.json({ success: true, data: null });
|
||||
return;
|
||||
}
|
||||
const profile = await getProfile();
|
||||
res.json({ success: true, data: profile });
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user