Fix for shopping list recipe delete route (#1954)

* fixed broken types

* changed remove recipe route from delete to post
This commit is contained in:
Michael Genson 2022-12-31 01:09:22 -06:00 committed by GitHub
parent 46cc3898ab
commit c4eebaccca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 14 deletions

View file

@ -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}`,
@ -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});
}
}

View file

@ -268,7 +268,7 @@ class ShoppingListController(BaseCrudController):
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
):

View file

@ -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
@ -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
@ -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(
@ -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,
)
@ -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,
)

View file

@ -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}"

View file

@ -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