mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 05:25:26 +02:00
Feature: Global Timeline (#2265)
* extended query filter to accept nested tables * decoupled timeline api from recipe slug * modified frontend to use simplified events api * fixed nested loop index ghosting * updated existing tests * gave mypy a snack * added tests for nested queries * fixed "last made" render error * decoupled recipe timeline from dialog * removed unused props * tweaked recipe get_all to accept ids * created group global timeline added new timeline page to sidebar reformatted the recipe timeline added vertical option to recipe card mobile * extracted timeline item into its own component * fixed apploader centering * added paginated scrolling to recipe timeline * added sort direction config fixed infinite scroll on dialog fixed hasMore var not resetting during instantiation * added sort direction to user preferences * updated API docs with new query filter feature * better error tracing * fix for recipe not found response * simplified recipe crud route for slug/id added test for fetching by slug/id * made query filter UUID validation clearer * moved timeline menu option below shopping lists --------- Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
This commit is contained in:
parent
0e397b34fd
commit
fe17922bb8
28 changed files with 871 additions and 506 deletions
|
@ -65,9 +65,11 @@ def test_recipe_migration(api_client: TestClient, unique_user: TestUser, mig: Mi
|
|||
response = api_client.get(api_routes.recipes, params=params, headers=unique_user.token)
|
||||
query_data = assert_derserialize(response)
|
||||
assert len(query_data["items"])
|
||||
slug = query_data["items"][0]["slug"]
|
||||
|
||||
response = api_client.get(api_routes.recipes_slug_timeline_events(slug), headers=unique_user.token)
|
||||
recipe_id = query_data["items"][0]["id"]
|
||||
params = {"queryFilter": f"recipe_id={recipe_id}"}
|
||||
|
||||
response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||
query_data = assert_derserialize(response)
|
||||
events = query_data["items"]
|
||||
assert len(events)
|
||||
|
|
|
@ -397,3 +397,30 @@ def test_delete_recipe_same_name(api_client: TestClient, unique_user: utils.Test
|
|||
response = api_client.get(api_routes.recipes_slug(slug), headers=unique_user.token)
|
||||
response = api_client.get(api_routes.recipes_slug(slug), headers=unique_user.token)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_get_recipe_by_slug_or_id(api_client: TestClient, unique_user: utils.TestUser):
|
||||
slugs = [random_string(10) for _ in range(3)]
|
||||
|
||||
# Create recipes
|
||||
for slug in slugs:
|
||||
response = api_client.post(api_routes.recipes, json={"name": slug}, headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
assert json.loads(response.text) == slug
|
||||
|
||||
# Get recipes by slug
|
||||
recipe_ids = []
|
||||
for slug in slugs:
|
||||
response = api_client.get(api_routes.recipes_slug(slug), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
recipe_data = response.json()
|
||||
assert recipe_data["slug"] == slug
|
||||
recipe_ids.append(recipe_data["id"])
|
||||
|
||||
# Get recipes by id
|
||||
for recipe_id, slug in zip(recipe_ids, slugs, strict=True):
|
||||
response = api_client.get(api_routes.recipes_slug(recipe_id), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
recipe_data = response.json()
|
||||
assert recipe_data["slug"] == slug
|
||||
assert recipe_data["id"] == recipe_id
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
@ -31,6 +33,7 @@ def recipes(api_client: TestClient, unique_user: TestUser):
|
|||
def test_create_timeline_event(api_client: TestClient, unique_user: TestUser, recipes: list[Recipe]):
|
||||
recipe = recipes[0]
|
||||
new_event = {
|
||||
"recipe_id": str(recipe.id),
|
||||
"user_id": unique_user.user_id,
|
||||
"subject": random_string(),
|
||||
"event_type": "info",
|
||||
|
@ -38,7 +41,7 @@ def test_create_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
}
|
||||
|
||||
event_response = api_client.post(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug),
|
||||
api_routes.recipes_timeline_events,
|
||||
json=new_event,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
|
@ -54,6 +57,7 @@ def test_get_all_timeline_events(api_client: TestClient, unique_user: TestUser,
|
|||
recipe = recipes[0]
|
||||
events_data = [
|
||||
{
|
||||
"recipe_id": str(recipe.id),
|
||||
"user_id": unique_user.user_id,
|
||||
"subject": random_string(),
|
||||
"event_type": "info",
|
||||
|
@ -64,17 +68,16 @@ def test_get_all_timeline_events(api_client: TestClient, unique_user: TestUser,
|
|||
|
||||
events: list[RecipeTimelineEventOut] = []
|
||||
for event_data in events_data:
|
||||
params: dict = {"queryFilter": f"recipe_id={event_data['recipe_id']}"}
|
||||
event_response = api_client.post(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug), json=event_data, headers=unique_user.token
|
||||
api_routes.recipes_timeline_events, params=params, json=event_data, headers=unique_user.token
|
||||
)
|
||||
events.append(RecipeTimelineEventOut.parse_obj(event_response.json()))
|
||||
|
||||
# check that we see them all
|
||||
params = {"page": 1, "perPage": -1}
|
||||
|
||||
events_response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug), params=params, headers=unique_user.token
|
||||
)
|
||||
events_response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||
events_pagination = RecipeTimelineEventPagination.parse_obj(events_response.json())
|
||||
|
||||
event_ids = [event.id for event in events]
|
||||
|
@ -89,6 +92,7 @@ def test_get_timeline_event(api_client: TestClient, unique_user: TestUser, recip
|
|||
# create an event
|
||||
recipe = recipes[0]
|
||||
new_event_data = {
|
||||
"recipe_id": str(recipe.id),
|
||||
"user_id": unique_user.user_id,
|
||||
"subject": random_string(),
|
||||
"event_type": "info",
|
||||
|
@ -96,16 +100,14 @@ def test_get_timeline_event(api_client: TestClient, unique_user: TestUser, recip
|
|||
}
|
||||
|
||||
event_response = api_client.post(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug),
|
||||
api_routes.recipes_timeline_events,
|
||||
json=new_event_data,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
new_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
|
||||
# fetch the new event
|
||||
event_response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events_item_id(recipe.slug, new_event.id), headers=unique_user.token
|
||||
)
|
||||
event_response = api_client.get(api_routes.recipes_timeline_events_item_id(new_event.id), headers=unique_user.token)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
|
@ -119,14 +121,13 @@ def test_update_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
# create an event
|
||||
recipe = recipes[0]
|
||||
new_event_data = {
|
||||
"recipe_id": str(recipe.id),
|
||||
"user_id": unique_user.user_id,
|
||||
"subject": old_subject,
|
||||
"event_type": "info",
|
||||
}
|
||||
|
||||
event_response = api_client.post(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug), json=new_event_data, headers=unique_user.token
|
||||
)
|
||||
event_response = api_client.post(api_routes.recipes_timeline_events, json=new_event_data, headers=unique_user.token)
|
||||
new_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
assert new_event.subject == old_subject
|
||||
|
||||
|
@ -134,7 +135,7 @@ def test_update_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
updated_event_data = {"subject": new_subject}
|
||||
|
||||
event_response = api_client.put(
|
||||
api_routes.recipes_slug_timeline_events_item_id(recipe.slug, new_event.id),
|
||||
api_routes.recipes_timeline_events_item_id(new_event.id),
|
||||
json=updated_event_data,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
|
@ -149,20 +150,19 @@ def test_delete_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
# create an event
|
||||
recipe = recipes[0]
|
||||
new_event_data = {
|
||||
"recipe_id": str(recipe.id),
|
||||
"user_id": unique_user.user_id,
|
||||
"subject": random_string(),
|
||||
"event_type": "info",
|
||||
"message": random_string(),
|
||||
}
|
||||
|
||||
event_response = api_client.post(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug), json=new_event_data, headers=unique_user.token
|
||||
)
|
||||
event_response = api_client.post(api_routes.recipes_timeline_events, json=new_event_data, headers=unique_user.token)
|
||||
new_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
|
||||
# delete the event
|
||||
event_response = api_client.delete(
|
||||
api_routes.recipes_slug_timeline_events_item_id(recipe.slug, new_event.id), headers=unique_user.token
|
||||
api_routes.recipes_timeline_events_item_id(new_event.id), headers=unique_user.token
|
||||
)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
|
@ -171,7 +171,7 @@ def test_delete_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
|
||||
# try to get the event
|
||||
event_response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events_item_id(recipe.slug, deleted_event.id), headers=unique_user.token
|
||||
api_routes.recipes_timeline_events_item_id(deleted_event.id), headers=unique_user.token
|
||||
)
|
||||
assert event_response.status_code == 404
|
||||
|
||||
|
@ -180,6 +180,7 @@ def test_timeline_event_message_alias(api_client: TestClient, unique_user: TestU
|
|||
# create an event using aliases
|
||||
recipe = recipes[0]
|
||||
new_event_data = {
|
||||
"recipeId": str(recipe.id),
|
||||
"userId": unique_user.user_id,
|
||||
"subject": random_string(),
|
||||
"eventType": "info",
|
||||
|
@ -187,7 +188,7 @@ def test_timeline_event_message_alias(api_client: TestClient, unique_user: TestU
|
|||
}
|
||||
|
||||
event_response = api_client.post(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug),
|
||||
api_routes.recipes_timeline_events,
|
||||
json=new_event_data,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
|
@ -197,9 +198,7 @@ def test_timeline_event_message_alias(api_client: TestClient, unique_user: TestU
|
|||
assert new_event.message == new_event_data["eventMessage"]
|
||||
|
||||
# fetch the new event
|
||||
event_response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events_item_id(recipe.slug, new_event.id), headers=unique_user.token
|
||||
)
|
||||
event_response = api_client.get(api_routes.recipes_timeline_events_item_id(new_event.id), headers=unique_user.token)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
|
@ -211,7 +210,7 @@ def test_timeline_event_message_alias(api_client: TestClient, unique_user: TestU
|
|||
updated_event_data = {"subject": new_subject, "eventMessage": new_message}
|
||||
|
||||
event_response = api_client.put(
|
||||
api_routes.recipes_slug_timeline_events_item_id(recipe.slug, new_event.id),
|
||||
api_routes.recipes_timeline_events_item_id(new_event.id),
|
||||
json=updated_event_data,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
|
@ -225,71 +224,20 @@ def test_timeline_event_message_alias(api_client: TestClient, unique_user: TestU
|
|||
def test_create_recipe_with_timeline_event(api_client: TestClient, unique_user: TestUser, recipes: list[Recipe]):
|
||||
# make sure when the recipes fixture was created that all recipes have at least one event
|
||||
for recipe in recipes:
|
||||
events_response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug), headers=unique_user.token
|
||||
)
|
||||
params = {"queryFilter": f"recipe_id={recipe.id}"}
|
||||
events_response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||
events_pagination = RecipeTimelineEventPagination.parse_obj(events_response.json())
|
||||
assert events_pagination.items
|
||||
|
||||
|
||||
def test_invalid_recipe_slug(api_client: TestClient, unique_user: TestUser):
|
||||
def test_invalid_recipe_id(api_client: TestClient, unique_user: TestUser):
|
||||
new_event_data = {
|
||||
"recipe_id": str(uuid4()),
|
||||
"user_id": unique_user.user_id,
|
||||
"subject": random_string(),
|
||||
"event_type": "info",
|
||||
"message": random_string(),
|
||||
}
|
||||
|
||||
event_response = api_client.post(
|
||||
api_routes.recipes_slug_timeline_events(random_string()), json=new_event_data, headers=unique_user.token
|
||||
)
|
||||
event_response = api_client.post(api_routes.recipes_timeline_events, json=new_event_data, headers=unique_user.token)
|
||||
assert event_response.status_code == 404
|
||||
|
||||
|
||||
def test_recipe_slug_mismatch(api_client: TestClient, unique_user: TestUser, recipes: list[Recipe]):
|
||||
# get new recipes
|
||||
recipe = recipes[0]
|
||||
invalid_recipe = recipes[1]
|
||||
|
||||
# create a new event
|
||||
new_event_data = {
|
||||
"user_id": unique_user.user_id,
|
||||
"subject": random_string(),
|
||||
"event_type": "info",
|
||||
"message": random_string(),
|
||||
}
|
||||
|
||||
event_response = api_client.post(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug), json=new_event_data, headers=unique_user.token
|
||||
)
|
||||
event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
|
||||
# try to perform operations on the event using the wrong recipe
|
||||
event_response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events_item_id(invalid_recipe.slug, event.id),
|
||||
headers=unique_user.token,
|
||||
)
|
||||
assert event_response.status_code == 404
|
||||
|
||||
event_response = api_client.put(
|
||||
api_routes.recipes_slug_timeline_events_item_id(invalid_recipe.slug, event.id),
|
||||
json=new_event_data,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
assert event_response.status_code == 404
|
||||
|
||||
event_response = api_client.delete(
|
||||
api_routes.recipes_slug_timeline_events_item_id(invalid_recipe.slug, event.id),
|
||||
headers=unique_user.token,
|
||||
)
|
||||
assert event_response.status_code == 404
|
||||
|
||||
# make sure the event still exists and is unmodified
|
||||
event_response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events_item_id(recipe.slug, event.id),
|
||||
headers=unique_user.token,
|
||||
)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
existing_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
assert existing_event == event
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import time
|
||||
from collections import defaultdict
|
||||
from random import randint
|
||||
from urllib.parse import parse_qsl, urlsplit
|
||||
|
||||
|
@ -11,13 +12,16 @@ from mealie.repos.repository_units import RepositoryUnit
|
|||
from mealie.schema.recipe.recipe_ingredient import IngredientUnit, SaveIngredientUnit
|
||||
from mealie.schema.response.pagination import PaginationQuery
|
||||
from mealie.services.seeder.seeder_service import SeederService
|
||||
from tests.utils import api_routes
|
||||
from tests.utils.factories import random_int, random_string
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
def test_repository_pagination(database: AllRepositories, unique_user: TestUser):
|
||||
group = database.groups.get_one(unique_user.group_id)
|
||||
assert group
|
||||
|
||||
seeder = SeederService(database, None, group)
|
||||
seeder = SeederService(database, None, group) # type: ignore
|
||||
seeder.seed_foods("en-US")
|
||||
|
||||
foods_repo = database.ingredient_foods.by_group(unique_user.group_id) # type: ignore
|
||||
|
@ -50,8 +54,9 @@ def test_repository_pagination(database: AllRepositories, unique_user: TestUser)
|
|||
|
||||
def test_pagination_response_and_metadata(database: AllRepositories, unique_user: TestUser):
|
||||
group = database.groups.get_one(unique_user.group_id)
|
||||
assert group
|
||||
|
||||
seeder = SeederService(database, None, group)
|
||||
seeder = SeederService(database, None, group) # type: ignore
|
||||
seeder.seed_foods("en-US")
|
||||
|
||||
foods_repo = database.ingredient_foods.by_group(unique_user.group_id) # type: ignore
|
||||
|
@ -78,8 +83,9 @@ def test_pagination_response_and_metadata(database: AllRepositories, unique_user
|
|||
|
||||
def test_pagination_guides(database: AllRepositories, unique_user: TestUser):
|
||||
group = database.groups.get_one(unique_user.group_id)
|
||||
assert group
|
||||
|
||||
seeder = SeederService(database, None, group)
|
||||
seeder = SeederService(database, None, group) # type: ignore
|
||||
seeder.seed_foods("en-US")
|
||||
|
||||
foods_repo = database.ingredient_foods.by_group(unique_user.group_id) # type: ignore
|
||||
|
@ -107,10 +113,10 @@ def test_pagination_guides(database: AllRepositories, unique_user: TestUser):
|
|||
random_page_of_results = foods_repo.page_all(query)
|
||||
random_page_of_results.set_pagination_guides(foods_route, query.dict())
|
||||
|
||||
next_params = dict(parse_qsl(urlsplit(random_page_of_results.next).query))
|
||||
next_params: dict = dict(parse_qsl(urlsplit(random_page_of_results.next).query)) # type: ignore
|
||||
assert int(next_params["page"]) == random_page + 1
|
||||
|
||||
prev_params = dict(parse_qsl(urlsplit(random_page_of_results.previous).query))
|
||||
prev_params: dict = dict(parse_qsl(urlsplit(random_page_of_results.previous).query)) # type: ignore
|
||||
assert int(prev_params["page"]) == random_page - 1
|
||||
|
||||
source_params = camelize(query.dict())
|
||||
|
@ -173,7 +179,7 @@ def test_pagination_filter_datetimes(
|
|||
unit_1 = query_units[1]
|
||||
unit_2 = query_units[2]
|
||||
|
||||
dt = unit_2.created_at.isoformat()
|
||||
dt = unit_2.created_at.isoformat() # type: ignore
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=f'createdAt>="{dt}"')
|
||||
unit_results = units_repo.page_all(query).items
|
||||
assert len(unit_results) == 2
|
||||
|
@ -194,7 +200,7 @@ def test_pagination_filter_advanced(query_units: tuple[RepositoryUnit, Ingredien
|
|||
units_repo = query_units[0]
|
||||
unit_3 = query_units[3]
|
||||
|
||||
dt = unit_3.created_at.isoformat()
|
||||
dt = str(unit_3.created_at.isoformat()) # type: ignore
|
||||
qf = f'name="test unit 1" OR (useAbbreviation=f AND (name="test unit 2" OR createdAt > "{dt}"))'
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=qf)
|
||||
unit_results = units_repo.page_all(query).items
|
||||
|
@ -206,8 +212,11 @@ def test_pagination_filter_advanced(query_units: tuple[RepositoryUnit, Ingredien
|
|||
"qf",
|
||||
[
|
||||
pytest.param('(name="test name" AND useAbbreviation=f))', id="unbalanced parenthesis"),
|
||||
pytest.param('id="this is not a valid UUID"', id="invalid UUID"),
|
||||
pytest.param('createdAt="this is not a valid datetime format"', id="invalid datetime format"),
|
||||
pytest.param('badAttribute="test value"', id="invalid attribute"),
|
||||
pytest.param('group.badAttribute="test value"', id="bad nested attribute"),
|
||||
pytest.param('group.preferences.badAttribute="test value"', id="bad double nested attribute"),
|
||||
],
|
||||
)
|
||||
def test_malformed_query_filters(api_client: TestClient, unique_user: TestUser, qf: str):
|
||||
|
@ -216,3 +225,46 @@ def test_malformed_query_filters(api_client: TestClient, unique_user: TestUser,
|
|||
|
||||
response = api_client.get(route, params={"queryFilter": qf}, headers=unique_user.token)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_pagination_filter_nested(api_client: TestClient, user_tuple: list[TestUser]):
|
||||
# create a few recipes for each user
|
||||
slugs: defaultdict[int, list[str]] = defaultdict(list)
|
||||
for i, user in enumerate(user_tuple):
|
||||
for _ in range(random_int(3, 5)):
|
||||
slug: str = random_string()
|
||||
response = api_client.post(api_routes.recipes, json={"name": slug}, headers=user.token)
|
||||
|
||||
assert response.status_code == 201
|
||||
slugs[i].append(slug)
|
||||
|
||||
# query recipes with a nested user filter
|
||||
recipe_ids: defaultdict[int, list[str]] = defaultdict(list)
|
||||
for i, user in enumerate(user_tuple):
|
||||
params = {"page": 1, "perPage": -1, "queryFilter": f'user.id="{user.user_id}"'}
|
||||
response = api_client.get(api_routes.recipes, params=params, headers=user.token)
|
||||
|
||||
assert response.status_code == 200
|
||||
recipes_data: list[dict] = response.json()["items"]
|
||||
assert recipes_data
|
||||
|
||||
for recipe_data in recipes_data:
|
||||
slug = recipe_data["slug"]
|
||||
assert slug in slugs[i]
|
||||
assert slug not in slugs[(i + 1) % len(user_tuple)]
|
||||
|
||||
recipe_ids[i].append(recipe_data["id"])
|
||||
|
||||
# query timeline events with a double nested recipe.user filter
|
||||
for i, user in enumerate(user_tuple):
|
||||
params = {"page": 1, "perPage": -1, "queryFilter": f'recipe.user.id="{user.user_id}"'}
|
||||
response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=user.token)
|
||||
|
||||
assert response.status_code == 200
|
||||
events_data: list[dict] = response.json()["items"]
|
||||
assert events_data
|
||||
|
||||
for event_data in events_data:
|
||||
recipe_id = event_data["recipeId"]
|
||||
assert recipe_id in recipe_ids[i]
|
||||
assert recipe_id not in recipe_ids[(i + 1) % len(user_tuple)]
|
||||
|
|
|
@ -5,9 +5,7 @@ from pydantic import UUID4
|
|||
|
||||
from mealie.schema.meal_plan.new_meal import CreatePlanEntry
|
||||
from mealie.schema.recipe.recipe import RecipeSummary
|
||||
from mealie.services.scheduler.tasks.create_timeline_events import (
|
||||
create_mealplan_timeline_events,
|
||||
)
|
||||
from mealie.services.scheduler.tasks.create_timeline_events import create_mealplan_timeline_events
|
||||
from tests import utils
|
||||
from tests.utils import api_routes
|
||||
from tests.utils.factories import random_int, random_string
|
||||
|
@ -31,7 +29,8 @@ def test_new_mealplan_event(api_client: TestClient, unique_user: TestUser):
|
|||
assert recipe.last_made is None
|
||||
|
||||
# store the number of events, so we can compare later
|
||||
response = api_client.get(api_routes.recipes_slug_timeline_events(recipe_name), headers=unique_user.token)
|
||||
params = {"queryFilter": f"recipe_id={recipe_id}"}
|
||||
response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||
response_json = response.json()
|
||||
initial_event_count = len(response_json["items"])
|
||||
|
||||
|
@ -45,10 +44,14 @@ def test_new_mealplan_event(api_client: TestClient, unique_user: TestUser):
|
|||
# run the task and check to make sure a new event was created from the mealplan
|
||||
create_mealplan_timeline_events()
|
||||
|
||||
params = {"page": "1", "perPage": "-1", "orderBy": "created_at", "orderDirection": "desc"}
|
||||
response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events(recipe_name), headers=unique_user.token, params=params
|
||||
)
|
||||
params = {
|
||||
"page": "1",
|
||||
"perPage": "-1",
|
||||
"orderBy": "created_at",
|
||||
"orderDirection": "desc",
|
||||
"queryFilter": f"recipe_id={recipe_id}",
|
||||
}
|
||||
response = api_client.get(api_routes.recipes_timeline_events, headers=unique_user.token, params=params)
|
||||
response_json = response.json()
|
||||
assert len(response_json["items"]) == initial_event_count + 1
|
||||
|
||||
|
@ -91,7 +94,8 @@ def test_new_mealplan_event_duplicates(api_client: TestClient, unique_user: Test
|
|||
recipe_id = recipe.id
|
||||
|
||||
# store the number of events, so we can compare later
|
||||
response = api_client.get(api_routes.recipes_slug_timeline_events(recipe_name), headers=unique_user.token)
|
||||
params = {"queryFilter": f"recipe_id={recipe_id}"}
|
||||
response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||
response_json = response.json()
|
||||
initial_event_count = len(response_json["items"])
|
||||
|
||||
|
@ -106,10 +110,14 @@ def test_new_mealplan_event_duplicates(api_client: TestClient, unique_user: Test
|
|||
for _ in range(3):
|
||||
create_mealplan_timeline_events()
|
||||
|
||||
params = {"page": "1", "perPage": "-1", "orderBy": "created_at", "orderDirection": "desc"}
|
||||
response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events(recipe_name), headers=unique_user.token, params=params
|
||||
)
|
||||
params = {
|
||||
"page": "1",
|
||||
"perPage": "-1",
|
||||
"orderBy": "created_at",
|
||||
"orderDirection": "desc",
|
||||
"queryFilter": f"recipe_id={recipe_id}",
|
||||
}
|
||||
response = api_client.get(api_routes.recipes_timeline_events, headers=unique_user.token, params=params)
|
||||
response_json = response.json()
|
||||
assert len(response_json["items"]) == initial_event_count + 1
|
||||
|
||||
|
@ -125,7 +133,8 @@ def test_new_mealplan_events_with_multiple_recipes(api_client: TestClient, uniqu
|
|||
recipes.append(RecipeSummary.parse_obj(response.json()))
|
||||
|
||||
# store the number of events, so we can compare later
|
||||
response = api_client.get(api_routes.recipes_slug_timeline_events(str(recipes[0].slug)), headers=unique_user.token)
|
||||
params = {"queryFilter": f"recipe_id={recipes[0].id}"}
|
||||
response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||
response_json = response.json()
|
||||
initial_event_count = len(response_json["items"])
|
||||
|
||||
|
@ -149,10 +158,14 @@ def test_new_mealplan_events_with_multiple_recipes(api_client: TestClient, uniqu
|
|||
|
||||
for recipe in recipes:
|
||||
target_count = initial_event_count + mealplan_count_by_recipe_id[recipe.id] # type: ignore
|
||||
params = {"page": "1", "perPage": "-1", "orderBy": "created_at", "orderDirection": "desc"}
|
||||
response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug), headers=unique_user.token, params=params
|
||||
)
|
||||
params = {
|
||||
"page": "1",
|
||||
"perPage": "-1",
|
||||
"orderBy": "created_at",
|
||||
"orderDirection": "desc",
|
||||
"queryFilter": f"recipe_id={recipe.id}",
|
||||
}
|
||||
response = api_client.get(api_routes.recipes_timeline_events, headers=unique_user.token, params=params)
|
||||
response_json = response.json()
|
||||
assert len(response_json["items"]) == target_count
|
||||
|
||||
|
@ -167,10 +180,9 @@ def test_new_mealplan_events_with_multiple_recipes(api_client: TestClient, uniqu
|
|||
"perPage": "-1",
|
||||
"orderBy": "created_at",
|
||||
"orderDirection": "desc",
|
||||
"queryFilter": f"recipe_id={recipe.id}",
|
||||
}
|
||||
response = api_client.get(
|
||||
api_routes.recipes_slug_timeline_events(recipe.slug), headers=unique_user.token, params=params
|
||||
)
|
||||
response = api_client.get(api_routes.recipes_timeline_events, headers=unique_user.token, params=params)
|
||||
response_json = response.json()
|
||||
assert len(response_json["items"]) == target_count
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ admin_server_tasks = "/api/admin/server-tasks"
|
|||
"""`/api/admin/server-tasks`"""
|
||||
admin_users = "/api/admin/users"
|
||||
"""`/api/admin/users`"""
|
||||
admin_users_password_reset_token = "/api/admin/users/password-reset-token"
|
||||
"""`/api/admin/users/password-reset-token`"""
|
||||
admin_users_unlock = "/api/admin/users/unlock"
|
||||
"""`/api/admin/users/unlock`"""
|
||||
app_about = "/api/app/about"
|
||||
|
@ -159,6 +161,8 @@ recipes_summary_untagged = "/api/recipes/summary/untagged"
|
|||
"""`/api/recipes/summary/untagged`"""
|
||||
recipes_test_scrape_url = "/api/recipes/test-scrape-url"
|
||||
"""`/api/recipes/test-scrape-url`"""
|
||||
recipes_timeline_events = "/api/recipes/timeline/events"
|
||||
"""`/api/recipes/timeline/events`"""
|
||||
shared_recipes = "/api/shared/recipes"
|
||||
"""`/api/shared/recipes`"""
|
||||
units = "/api/units"
|
||||
|
@ -386,14 +390,9 @@ def recipes_slug_last_made(slug):
|
|||
return f"{prefix}/recipes/{slug}/last-made"
|
||||
|
||||
|
||||
def recipes_slug_timeline_events(slug):
|
||||
"""`/api/recipes/{slug}/timeline/events`"""
|
||||
return f"{prefix}/recipes/{slug}/timeline/events"
|
||||
|
||||
|
||||
def recipes_slug_timeline_events_item_id(slug, item_id):
|
||||
"""`/api/recipes/{slug}/timeline/events/{item_id}`"""
|
||||
return f"{prefix}/recipes/{slug}/timeline/events/{item_id}"
|
||||
def recipes_timeline_events_item_id(item_id):
|
||||
"""`/api/recipes/timeline/events/{item_id}`"""
|
||||
return f"{prefix}/recipes/timeline/events/{item_id}"
|
||||
|
||||
|
||||
def shared_recipes_item_id(item_id):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue