mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-25 08:09:41 +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
|
@ -33,6 +33,7 @@ from mealie.schema.response.pagination import (
|
|||
OrderDirection,
|
||||
PaginationQuery,
|
||||
)
|
||||
from mealie.schema.user.user import UserRatingUpdate
|
||||
from mealie.services.seeder.seeder_service import SeederService
|
||||
from tests.utils import api_routes
|
||||
from tests.utils.factories import random_int, random_string
|
||||
|
@ -1320,3 +1321,105 @@ def test_pagination_filter_nested(api_client: TestClient, user_tuple: list[TestU
|
|||
recipe_id = event_data["recipeId"]
|
||||
assert recipe_id in recipe_ids[i]
|
||||
assert recipe_id not in recipe_ids[(i + 1) % len(user_tuple)]
|
||||
|
||||
|
||||
def test_pagination_filter_by_custom_last_made(api_client: TestClient, unique_user: TestUser, h2_user: TestUser):
|
||||
recipe_1, recipe_2 = (
|
||||
unique_user.repos.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=random_string())
|
||||
)
|
||||
for _ in range(2)
|
||||
)
|
||||
dt_1 = "2023-02-25"
|
||||
dt_2 = "2023-03-25"
|
||||
|
||||
r = api_client.patch(
|
||||
api_routes.recipes_slug_last_made(recipe_1.slug),
|
||||
json={"timestamp": dt_1},
|
||||
headers=unique_user.token,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
r = api_client.patch(
|
||||
api_routes.recipes_slug_last_made(recipe_2.slug),
|
||||
json={"timestamp": dt_2},
|
||||
headers=unique_user.token,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
r = api_client.patch(
|
||||
api_routes.recipes_slug_last_made(recipe_1.slug),
|
||||
json={"timestamp": dt_2},
|
||||
headers=h2_user.token,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
r = api_client.patch(
|
||||
api_routes.recipes_slug_last_made(recipe_2.slug),
|
||||
json={"timestamp": dt_1},
|
||||
headers=h2_user.token,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
params = {"page": 1, "perPage": -1, "queryFilter": "lastMade > 2023-03-01"}
|
||||
|
||||
# User 1 should fetch Recipe 2
|
||||
response = api_client.get(api_routes.recipes, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
recipes_data = response.json()["items"]
|
||||
assert len(recipes_data) == 1
|
||||
assert recipes_data[0]["id"] == str(recipe_2.id)
|
||||
|
||||
# User 2 should fetch Recipe 1
|
||||
response = api_client.get(api_routes.recipes, params=params, headers=h2_user.token)
|
||||
assert response.status_code == 200
|
||||
recipes_data = response.json()["items"]
|
||||
assert len(recipes_data) == 1
|
||||
assert recipes_data[0]["id"] == str(recipe_1.id)
|
||||
|
||||
|
||||
def test_pagination_filter_by_custom_rating(api_client: TestClient, user_tuple: list[TestUser]):
|
||||
user_1, user_2 = user_tuple
|
||||
recipe_1, recipe_2 = (
|
||||
user_1.repos.recipes.create(Recipe(user_id=user_1.user_id, group_id=user_1.group_id, name=random_string()))
|
||||
for _ in range(2)
|
||||
)
|
||||
|
||||
r = api_client.post(
|
||||
api_routes.users_id_ratings_slug(user_1.user_id, recipe_1.slug),
|
||||
json=UserRatingUpdate(rating=5).model_dump(),
|
||||
headers=user_1.token,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
r = api_client.post(
|
||||
api_routes.users_id_ratings_slug(user_1.user_id, recipe_2.slug),
|
||||
json=UserRatingUpdate(rating=1).model_dump(),
|
||||
headers=user_1.token,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
r = api_client.post(
|
||||
api_routes.users_id_ratings_slug(user_2.user_id, recipe_1.slug),
|
||||
json=UserRatingUpdate(rating=1).model_dump(),
|
||||
headers=user_2.token,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
r = api_client.post(
|
||||
api_routes.users_id_ratings_slug(user_2.user_id, recipe_2.slug),
|
||||
json=UserRatingUpdate(rating=5).model_dump(),
|
||||
headers=user_2.token,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
qf = "rating > 3"
|
||||
params = {"page": 1, "perPage": -1, "queryFilter": qf}
|
||||
|
||||
# User 1 should fetch Recipe 1
|
||||
response = api_client.get(api_routes.recipes, params=params, headers=user_1.token)
|
||||
assert response.status_code == 200
|
||||
recipes_data = response.json()["items"]
|
||||
assert len(recipes_data) == 1
|
||||
assert recipes_data[0]["id"] == str(recipe_1.id)
|
||||
|
||||
# User 2 should fetch Recipe 2
|
||||
response = api_client.get(api_routes.recipes, params=params, headers=user_2.token)
|
||||
assert response.status_code == 200
|
||||
recipes_data = response.json()["items"]
|
||||
assert len(recipes_data) == 1
|
||||
assert recipes_data[0]["id"] == str(recipe_2.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue