feat(shopping): clearCart
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m14s

This commit is contained in:
hsiegeln
2026-04-21 23:13:58 +02:00
parent 974227590f
commit 2c61d82935
2 changed files with 26 additions and 3 deletions

View File

@@ -187,6 +187,10 @@ export function clearCheckedItems(db: Database.Database): void {
tx();
}
export function clearCart(_db: Database.Database): void {
throw new Error('not implemented');
export function clearCart(db: Database.Database): void {
const tx = db.transaction(() => {
db.prepare('DELETE FROM shopping_cart_recipe').run();
db.prepare('DELETE FROM shopping_cart_check').run();
});
tx();
}

View File

@@ -7,7 +7,8 @@ import {
listShoppingList,
setCartServings,
toggleCheck,
clearCheckedItems
clearCheckedItems,
clearCart
} from '../../src/lib/server/shopping/repository';
import type { Recipe } from '../../src/lib/types';
@@ -285,3 +286,21 @@ describe('clearCheckedItems', () => {
expect(listShoppingList(db).recipes).toHaveLength(1);
});
});
describe('clearCart', () => {
it('deletes all cart recipes and all checks', () => {
const db = openInMemoryForTest();
const id = insertRecipe(db, recipe({
ingredients: [{ position: 1, quantity: 1, unit: 'Stk', name: 'Apfel', note: null, raw_text: '', section_heading: null }]
}));
addRecipeToCart(db, id, null);
toggleCheck(db, 'apfel', 'stk', true);
clearCart(db);
const snap = listShoppingList(db);
expect(snap.recipes).toEqual([]);
expect(snap.rows).toEqual([]);
expect(snap.uncheckedCount).toBe(0);
const anyCheck = db.prepare('SELECT 1 FROM shopping_cart_check').get();
expect(anyCheck).toBeUndefined();
});
});