feat(planner): add server.test.ts for GET /planner, fix sort + add error handling
- Sort uses scoreDelta instead of removed simulatedScore - try/catch degrades gracefully to suggestions=[] on backend errors - 6 tests cover: missing params, success, backend error, network throw, empty result Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,14 +11,18 @@ export const GET: RequestHandler = async ({ fetch, url }) => {
|
||||
return json({ suggestions: [] });
|
||||
}
|
||||
|
||||
const api = apiClient(fetch);
|
||||
const { data } = await api.GET('/v1/week-plans/{id}/suggestions', {
|
||||
params: { path: { id: planId }, query: { slotDate: date } }
|
||||
});
|
||||
try {
|
||||
const api = apiClient(fetch);
|
||||
const { data } = await api.GET('/v1/week-plans/{id}/suggestions', {
|
||||
params: { path: { id: planId }, query: { slotDate: date } }
|
||||
});
|
||||
|
||||
const suggestions = (data?.suggestions ?? []).sort(
|
||||
(a: any, b: any) => (b.simulatedScore ?? 0) - (a.simulatedScore ?? 0)
|
||||
);
|
||||
const suggestions = (data?.suggestions ?? []).sort(
|
||||
(a: any, b: any) => (b.scoreDelta ?? 0) - (a.scoreDelta ?? 0)
|
||||
);
|
||||
|
||||
return json({ suggestions });
|
||||
return json({ suggestions });
|
||||
} catch {
|
||||
return json({ suggestions: [] });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user