mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 05:25:26 +02:00
feat: add support for API extras on shopping lists, shopping list items, and food data (#1619)
* added api extras to other tables genericized api extras model from recipes added extras column to ingredient foods added extras column to shopping lists added extras column to shopping list items * updated alembic version test * made mypy happy * added TODO on test that does nothing * added extras tests for lists, items, and foods * added docs for new extras * modified alembic versions to eliminate branching
This commit is contained in:
parent
db70a210a2
commit
8271c3001e
12 changed files with 300 additions and 33 deletions
|
@ -1,7 +1,10 @@
|
|||
from collections.abc import Generator
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from mealie.schema.recipe.recipe_ingredient import CreateIngredientFood
|
||||
from tests import utils
|
||||
from tests.utils.factories import random_string
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
@ -9,12 +12,13 @@ from tests.utils.fixture_schemas import TestUser
|
|||
class Routes:
|
||||
base = "/api/foods"
|
||||
|
||||
@staticmethod
|
||||
def item(item_id: int) -> str:
|
||||
return f"{Routes.base}/{item_id}"
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def food(api_client: TestClient, unique_user: TestUser) -> dict:
|
||||
def food(api_client: TestClient, unique_user: TestUser) -> Generator[dict, None, None]:
|
||||
data = CreateIngredientFood(
|
||||
name=random_string(10),
|
||||
description=random_string(10),
|
||||
|
@ -74,3 +78,39 @@ def test_delete_food(api_client: TestClient, food: dict, unique_user: TestUser):
|
|||
|
||||
response = api_client.get(Routes.item(id), headers=unique_user.token)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_food_extras(
|
||||
api_client: TestClient,
|
||||
unique_user: TestUser,
|
||||
):
|
||||
key_str_1 = random_string()
|
||||
val_str_1 = random_string()
|
||||
|
||||
key_str_2 = random_string()
|
||||
val_str_2 = random_string()
|
||||
|
||||
# create a food with extras
|
||||
new_food_data: dict = {"name": random_string()}
|
||||
new_food_data["extras"] = {key_str_1: val_str_1}
|
||||
|
||||
response = api_client.post(Routes.base, json=new_food_data, headers=unique_user.token)
|
||||
food_as_json = utils.assert_derserialize(response, 201)
|
||||
|
||||
# make sure the extra persists
|
||||
extras = food_as_json["extras"]
|
||||
assert key_str_1 in extras
|
||||
assert extras[key_str_1] == val_str_1
|
||||
|
||||
# add more extras to the food
|
||||
food_as_json["extras"][key_str_2] = val_str_2
|
||||
|
||||
response = api_client.put(Routes.item(food_as_json["id"]), json=food_as_json, headers=unique_user.token)
|
||||
food_as_json = utils.assert_derserialize(response, 200)
|
||||
|
||||
# make sure both the new extra and original extra persist
|
||||
extras = food_as_json["extras"]
|
||||
assert key_str_1 in extras
|
||||
assert key_str_2 in extras
|
||||
assert extras[key_str_1] == val_str_1
|
||||
assert extras[key_str_2] == val_str_2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue