feat(staples): A3/D3 — Pantry staples toggle UI #35

Merged
marcel merged 17 commits from feat/issue-20-pantry-staples into master 2026-04-03 09:35:03 +02:00
2 changed files with 11 additions and 2 deletions
Showing only changes of commit 3581af2bf9 - Show all commits

View File

@@ -21,7 +21,8 @@ export const PATCH: RequestHandler = async ({ request, fetch }) => {
});
if (error) {
return json({ error: 'Failed to update ingredient' }, { status: 500 });
const status = (error as { status?: number }).status ?? 500;
return json({ error: 'Failed to update ingredient' }, { status });
}
return new Response(null, { status: 204 });

View File

@@ -46,7 +46,7 @@ describe('household staples PATCH handler', () => {
expect(response.status).toBe(204);
});
it('returns 500 when backend returns an error', async () => {
it('returns 500 when backend returns a 500 error', async () => {
mockPatch.mockResolvedValue({ data: undefined, error: { status: 500, message: 'error' } });
const response = await PATCH(createRequest({ id: 'ing-1', isStaple: false }));
@@ -54,6 +54,14 @@ describe('household staples PATCH handler', () => {
expect(response.status).toBe(500);
});
it('forwards backend 404 status when ingredient not found', async () => {
mockPatch.mockResolvedValue({ data: undefined, error: { status: 404 } });
const response = await PATCH(createRequest({ id: 'ing-1', isStaple: false }));
expect(response.status).toBe(404);
});
it('returns 400 when id is missing', async () => {
const response = await PATCH(createRequest({ isStaple: true }));