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:
2026-04-09 11:39:50 +02:00
committed by marcel
parent 8234c2f162
commit a751b0758a
2 changed files with 103 additions and 8 deletions

View File

@@ -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: [] });
}
};