Skip to content

Commit

Permalink
Fix for shopping list recipe delete route (#1954)
Browse files Browse the repository at this point in the history
* fixed broken types

* changed remove recipe route from delete to post
  • Loading branch information
michael-genson authored Dec 31, 2022
1 parent 46cc389 commit c4eebac
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
5 changes: 3 additions & 2 deletions frontend/lib/api/user/group-shopping-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const routes = {
shoppingLists: `${prefix}/groups/shopping/lists`,
shoppingListsId: (id: string) => `${prefix}/groups/shopping/lists/${id}`,
shoppingListIdAddRecipe: (id: string, recipeId: string) => `${prefix}/groups/shopping/lists/${id}/recipe/${recipeId}`,
shoppingListIdRemoveRecipe: (id: string, recipeId: string) => `${prefix}/groups/shopping/lists/${id}/recipe/${recipeId}/delete`,

shoppingListItems: `${prefix}/groups/shopping/items`,
shoppingListItemsId: (id: string) => `${prefix}/groups/shopping/items/${id}`,
Expand All @@ -28,8 +29,8 @@ export class ShoppingListsApi extends BaseCRUDAPI<ShoppingListCreate, ShoppingLi
return await this.requests.post(routes.shoppingListIdAddRecipe(itemId, recipeId), {recipeIncrementQuantity});
}

async removeRecipe(itemId: string, recipeId: string) {
return await this.requests.delete(routes.shoppingListIdAddRecipe(itemId, recipeId));
async removeRecipe(itemId: string, recipeId: string, recipeDecrementQuantity = 1) {
return await this.requests.post(routes.shoppingListIdRemoveRecipe(itemId, recipeId), {recipeDecrementQuantity});
}
}

Expand Down
2 changes: 1 addition & 1 deletion mealie/routes/groups/controller_shopping_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def add_recipe_ingredients_to_list(

return shopping_list

@router.delete("/{item_id}/recipe/{recipe_id}", response_model=ShoppingListOut)
@router.post("/{item_id}/recipe/{recipe_id}/delete", response_model=ShoppingListOut)
def remove_recipe_ingredients_from_list(
self, item_id: UUID4, recipe_id: UUID4, data: ShoppingListRemoveRecipeParams | None = None
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ def test_shopping_lists_remove_recipe(
assert item["note"] in known_ingredients

# Remove Recipe
response = api_client.delete(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id), headers=unique_user.token
response = api_client.post(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id_delete(sample_list.id, recipe.id),
headers=unique_user.token,
)

# Get List and Check for Ingredients
Expand Down Expand Up @@ -241,8 +242,9 @@ def test_shopping_lists_remove_recipe_multiple_quantity(
assert item["note"] in known_ingredients

# Remove Recipe
response = api_client.delete(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id), headers=unique_user.token
response = api_client.post(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id_delete(sample_list.id, recipe.id),
headers=unique_user.token,
)

# Get List and Check for Ingredients
Expand Down Expand Up @@ -271,7 +273,7 @@ def test_shopping_list_remove_recipe_scale(
recipe = recipe_ingredient_only

recipe_initital_scale = 100
payload = {"recipeIncrementQuantity": recipe_initital_scale}
payload: dict = {"recipeIncrementQuantity": recipe_initital_scale}

# first add a bunch of quantity to the list
response = api_client.post(
Expand Down Expand Up @@ -299,8 +301,8 @@ def test_shopping_list_remove_recipe_scale(
recipe_expected_scale = recipe_initital_scale - recipe_decrement_scale

# remove some of the recipes
response = api_client.delete(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id),
response = api_client.post(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id_delete(sample_list.id, recipe.id),
headers=unique_user.token,
json=payload,
)
Expand Down Expand Up @@ -366,8 +368,8 @@ def test_recipe_decrement_max(

# now remove way too many instances of the recipe
payload = {"recipeDecrementQuantity": recipe_scale * 100}
response = api_client.delete(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id),
response = api_client.post(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id_delete(sample_list.id, recipe.id),
headers=unique_user.token,
json=payload,
)
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/api_routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ def groups_shopping_lists_item_id_recipe_recipe_id(item_id, recipe_id):
return f"{prefix}/groups/shopping/lists/{item_id}/recipe/{recipe_id}"


def groups_shopping_lists_item_id_recipe_recipe_id_delete(item_id, recipe_id):
"""`/api/groups/shopping/lists/{item_id}/recipe/{recipe_id}/delete`"""
return f"{prefix}/groups/shopping/lists/{item_id}/recipe/{recipe_id}/delete"


def groups_webhooks_item_id(item_id):
"""`/api/groups/webhooks/{item_id}`"""
return f"{prefix}/groups/webhooks/{item_id}"
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/assertion_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from requests import Response
from httpx import Response


def assert_ignore_keys(dict1: dict, dict2: dict, ignore_keys: list = None) -> None:
def assert_ignore_keys(dict1: dict, dict2: dict, ignore_keys: list | None = None) -> None:
"""
Itterates through a list of keys and checks if they are in the the provided ignore_keys list,
if they are not in the ignore_keys list, it checks the value of the key in the provided against
Expand Down

0 comments on commit c4eebac

Please sign in to comment.