mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-06 14:05:21 +02:00
feat: Move "on hand" and "last made" to household (#4616)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
e565b919df
commit
e9892aba89
53 changed files with 1618 additions and 400 deletions
|
@ -1,6 +1,13 @@
|
|||
from datetime import datetime, timezone
|
||||
from uuid import UUID
|
||||
|
||||
from dateutil.parser import parse as parse_dt
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from mealie.db.models.household import HouseholdToRecipe
|
||||
from mealie.schema.recipe.recipe import Recipe
|
||||
from tests.utils import api_routes
|
||||
from tests.utils.factories import random_string
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
|
@ -18,3 +25,61 @@ def test_get_household_members(api_client: TestClient, user_tuple: list[TestUser
|
|||
assert str(usr_1.user_id) in all_ids
|
||||
assert str(usr_2.user_id) in all_ids
|
||||
assert str(h2_user.user_id) not in all_ids
|
||||
|
||||
|
||||
def test_get_household_recipe_default(api_client: TestClient, unique_user: TestUser):
|
||||
recipe = unique_user.repos.recipes.create(
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=UUID(unique_user.group_id),
|
||||
name=random_string(),
|
||||
)
|
||||
)
|
||||
response = api_client.get(api_routes.households_self_recipes_recipe_slug(recipe.slug), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["recipeId"] == str(recipe.id)
|
||||
assert response.json()["lastMade"] is None
|
||||
|
||||
|
||||
def test_get_household_recipe(api_client: TestClient, unique_user: TestUser, h2_user: TestUser):
|
||||
dt_now = datetime.now(tz=timezone.utc)
|
||||
recipe = unique_user.repos.recipes.create(
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=UUID(unique_user.group_id),
|
||||
name=random_string(),
|
||||
)
|
||||
)
|
||||
|
||||
session = unique_user.repos.session
|
||||
session.add(
|
||||
HouseholdToRecipe(
|
||||
session=session,
|
||||
household_id=UUID(unique_user.household_id),
|
||||
recipe_id=recipe.id,
|
||||
last_made=dt_now,
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
response = api_client.get(api_routes.households_self_recipes_recipe_slug(recipe.slug), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.json()
|
||||
assert data["recipeId"] == str(recipe.id)
|
||||
assert data["lastMade"]
|
||||
assert parse_dt(data["lastMade"]) == dt_now
|
||||
|
||||
response = api_client.get(api_routes.households_self_recipes_recipe_slug(recipe.slug), headers=h2_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
h2_data = response.json()
|
||||
assert h2_data["recipeId"] == str(recipe.id)
|
||||
assert h2_data["lastMade"] is None
|
||||
|
||||
|
||||
def test_get_household_recipe_invalid_recipe(api_client: TestClient, unique_user: TestUser):
|
||||
response = api_client.get(
|
||||
api_routes.households_self_recipes_recipe_slug(random_string()), headers=unique_user.token
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue