feat(shopping): removeRecipeFromCart
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m27s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m27s
This commit is contained in:
@@ -3,6 +3,7 @@ import { openInMemoryForTest } from '../../src/lib/server/db';
|
||||
import { insertRecipe } from '../../src/lib/server/recipes/repository';
|
||||
import {
|
||||
addRecipeToCart,
|
||||
removeRecipeFromCart,
|
||||
listShoppingList
|
||||
} from '../../src/lib/server/shopping/repository';
|
||||
import type { Recipe } from '../../src/lib/types';
|
||||
@@ -63,3 +64,23 @@ describe('addRecipeToCart', () => {
|
||||
expect(listShoppingList(db).recipes[0].servings).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeRecipeFromCart', () => {
|
||||
it('deletes only the given recipe', () => {
|
||||
const db = openInMemoryForTest();
|
||||
const a = insertRecipe(db, recipe({ title: 'A' }));
|
||||
const b = insertRecipe(db, recipe({ title: 'B' }));
|
||||
addRecipeToCart(db, a, null);
|
||||
addRecipeToCart(db, b, null);
|
||||
removeRecipeFromCart(db, a);
|
||||
const snap = listShoppingList(db);
|
||||
expect(snap.recipes).toHaveLength(1);
|
||||
expect(snap.recipes[0].recipe_id).toBe(b);
|
||||
});
|
||||
|
||||
it('is idempotent when recipe is not in cart', () => {
|
||||
const db = openInMemoryForTest();
|
||||
const id = insertRecipe(db, recipe());
|
||||
expect(() => removeRecipeFromCart(db, id)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user