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:
@@ -47,8 +47,11 @@ export function addRecipeToCart(
|
|||||||
).run(recipeId, resolved, profileId);
|
).run(recipeId, resolved, profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeRecipeFromCart(_db: Database.Database, _recipeId: number): void {
|
export function removeRecipeFromCart(
|
||||||
throw new Error('not implemented');
|
db: Database.Database,
|
||||||
|
recipeId: number
|
||||||
|
): void {
|
||||||
|
db.prepare('DELETE FROM shopping_cart_recipe WHERE recipe_id = ?').run(recipeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setCartServings(
|
export function setCartServings(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { openInMemoryForTest } from '../../src/lib/server/db';
|
|||||||
import { insertRecipe } from '../../src/lib/server/recipes/repository';
|
import { insertRecipe } from '../../src/lib/server/recipes/repository';
|
||||||
import {
|
import {
|
||||||
addRecipeToCart,
|
addRecipeToCart,
|
||||||
|
removeRecipeFromCart,
|
||||||
listShoppingList
|
listShoppingList
|
||||||
} 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';
|
||||||
@@ -63,3 +64,23 @@ describe('addRecipeToCart', () => {
|
|||||||
expect(listShoppingList(db).recipes[0].servings).toBe(4);
|
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