Public Access
feat(meals): enforce three lower-calorie dinners with media
This commit is contained in:
@@ -87,3 +87,93 @@ def test_generate_meal_plan_against_seeded_data():
|
||||
finally:
|
||||
cleanup.close()
|
||||
work.close()
|
||||
|
||||
|
||||
def test_generate_meal_plan_uses_three_active_calorie_eligible_recipes(db):
|
||||
from app.models import (
|
||||
FamilyProfile,
|
||||
MealPlanItem,
|
||||
MealType,
|
||||
Recipe,
|
||||
RecipeCatalogStatus,
|
||||
)
|
||||
from app.services.planner.generate import generate_meal_plan
|
||||
|
||||
db.query(Recipe).update(
|
||||
{Recipe.catalog_status: RecipeCatalogStatus.QUARANTINED},
|
||||
synchronize_session=False,
|
||||
)
|
||||
family = FamilyProfile(
|
||||
id=uuid4(),
|
||||
name="Three Dinner Family",
|
||||
household_size=2,
|
||||
adult_count=2,
|
||||
child_count=0,
|
||||
calorie_target=400,
|
||||
planner_config={"set_size": 7},
|
||||
)
|
||||
db.add(family)
|
||||
|
||||
eligible = [
|
||||
Recipe(
|
||||
id=uuid4(),
|
||||
name=f"Lower Calorie Dinner {index}",
|
||||
servings=4,
|
||||
calories_per_serving=calories,
|
||||
prep_time_minutes=10,
|
||||
cook_time_minutes=20,
|
||||
ingredients=[],
|
||||
instructions=["Cook."],
|
||||
catalog_status=RecipeCatalogStatus.ACTIVE,
|
||||
)
|
||||
for index, calories in enumerate((360, 400, 440), start=1)
|
||||
]
|
||||
high_calorie = Recipe(
|
||||
id=uuid4(),
|
||||
name="Old High Calorie Dinner",
|
||||
servings=4,
|
||||
calories_per_serving=700,
|
||||
prep_time_minutes=10,
|
||||
cook_time_minutes=20,
|
||||
ingredients=[],
|
||||
instructions=["Cook."],
|
||||
catalog_status=RecipeCatalogStatus.ACTIVE,
|
||||
)
|
||||
quarantined = Recipe(
|
||||
id=uuid4(),
|
||||
name="Quarantined Legacy Dinner",
|
||||
servings=4,
|
||||
calories_per_serving=400,
|
||||
prep_time_minutes=10,
|
||||
cook_time_minutes=20,
|
||||
ingredients=[],
|
||||
instructions=["Cook."],
|
||||
catalog_status=RecipeCatalogStatus.QUARANTINED,
|
||||
)
|
||||
db.add_all([*eligible, high_calorie, quarantined])
|
||||
db.flush()
|
||||
|
||||
result = generate_meal_plan(
|
||||
db,
|
||||
family_id=family.id,
|
||||
week_start_date=date(2026, 8, 31),
|
||||
today=date(2026, 8, 31),
|
||||
)
|
||||
|
||||
items = (
|
||||
db.query(MealPlanItem)
|
||||
.filter(MealPlanItem.meal_plan_id == result.meal_plan_id)
|
||||
.order_by(MealPlanItem.day_of_week)
|
||||
.all()
|
||||
)
|
||||
assert {selected.recipe_id for selected in result.selected} == {
|
||||
recipe.id for recipe in eligible
|
||||
}
|
||||
assert [(item.day_of_week, item.meal_type) for item in items] == [
|
||||
(1, MealType.DINNER),
|
||||
(3, MealType.DINNER),
|
||||
(5, MealType.DINNER),
|
||||
]
|
||||
assert high_calorie.id not in {item.recipe_id for item in items}
|
||||
assert quarantined.id not in {item.recipe_id for item in items}
|
||||
assert result.rejected_summary["calories"] == 1
|
||||
|
||||
Reference in New Issue
Block a user