feat(shopping): clearCart
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m14s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m14s
This commit is contained in:
@@ -187,6 +187,10 @@ export function clearCheckedItems(db: Database.Database): void {
|
|||||||
tx();
|
tx();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearCart(_db: Database.Database): void {
|
export function clearCart(db: Database.Database): void {
|
||||||
throw new Error('not implemented');
|
const tx = db.transaction(() => {
|
||||||
|
db.prepare('DELETE FROM shopping_cart_recipe').run();
|
||||||
|
db.prepare('DELETE FROM shopping_cart_check').run();
|
||||||
|
});
|
||||||
|
tx();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import {
|
|||||||
listShoppingList,
|
listShoppingList,
|
||||||
setCartServings,
|
setCartServings,
|
||||||
toggleCheck,
|
toggleCheck,
|
||||||
clearCheckedItems
|
clearCheckedItems,
|
||||||
|
clearCart
|
||||||
} from '../../src/lib/server/shopping/repository';
|
} from '../../src/lib/server/shopping/repository';
|
||||||
import type { Recipe } from '../../src/lib/types';
|
import type { Recipe } from '../../src/lib/types';
|
||||||
|
|
||||||
@@ -285,3 +286,21 @@ describe('clearCheckedItems', () => {
|
|||||||
expect(listShoppingList(db).recipes).toHaveLength(1);
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user