feat: add RecipeCreate/Update/Read schemas with canonical ingredient refs

This commit is contained in:
2026-05-05 20:50:07 -07:00
parent c8382b37e7
commit be7f698779
2 changed files with 116 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
from uuid import uuid4
import pytest
from pydantic import ValidationError
from app.schemas.recipe import RecipeCreate, RecipeIngredientRef, ResolveIngredientRequest
def test_recipe_create_requires_canonical_ingredient_ids() -> None:
iid = uuid4()
payload = RecipeCreate(
name="Sheet-Pan Chicken Thighs",
servings=4,
prep_time_minutes=10,
cook_time_minutes=30,
cuisine_tags=["american"],
protein_type="chicken",
ingredients=[RecipeIngredientRef(ingredient_id=iid, qty=2.0, unit="lb")],
instructions=["Preheat oven", "Roast"],
)
assert payload.ingredients[0].ingredient_id == iid
assert payload.servings == 4
def test_recipe_create_rejects_empty_ingredients() -> None:
with pytest.raises(ValidationError):
RecipeCreate(
name="Empty",
servings=4,
prep_time_minutes=5,
cook_time_minutes=5,
cuisine_tags=[],
protein_type="vegetarian",
ingredients=[],
instructions=["nope"],
)
def test_resolve_ingredient_request_round_trip() -> None:
req = ResolveIngredientRequest(text="1 lb chicken thighs")
assert req.text == "1 lb chicken thighs"