""" Tests for constraints.py — all four owned/budget combinations. """ import pytest from unittest.mock import MagicMock from app.services.ai.constraints import build_constraint_context, build_owned_card_list from app.schemas.deck import DeckConstraints def make_constraints(prefer_owned=False, budget_enabled=False, budget_amount=None, budget_scope="purchase"): c = MagicMock(spec=DeckConstraints) c.prefer_owned = prefer_owned c.budget_enabled = budget_enabled c.budget_amount = budget_amount c.budget_scope = budget_scope return c class TestBuildConstraintContext: def test_no_constraints(self): c = make_constraints() result = build_constraint_context(c, None) assert "No special constraints" in result def test_prefer_owned_with_cards(self): c = make_constraints(prefer_owned=True) result = build_constraint_context(c, ["Sol Ring", "Command Tower"]) assert "Prefer cards the user already owns" in result assert "[UNOWNED]" in result def test_prefer_owned_without_cards(self): c = make_constraints(prefer_owned=True) result = build_constraint_context(c, []) assert "No special constraints" in result def test_budget_only(self): c = make_constraints(budget_enabled=True, budget_amount=100.0, budget_scope="purchase") result = build_constraint_context(c, None) assert "$100.00" in result assert "cards to purchase" in result def test_budget_total_scope(self): c = make_constraints(budget_enabled=True, budget_amount=200.0, budget_scope="total") result = build_constraint_context(c, None) assert "total deck" in result def test_owned_and_budget(self): c = make_constraints(prefer_owned=True, budget_enabled=True, budget_amount=50.0) result = build_constraint_context(c, ["Sol Ring"]) assert "Prefer cards" in result assert "$50.00" in result def test_budget_disabled_no_amount(self): c = make_constraints(budget_enabled=False, budget_amount=100.0) result = build_constraint_context(c, None) assert "$100.00" not in result class TestBuildOwnedCardList: def test_empty_list(self): result = build_owned_card_list([]) assert result == "" def test_cards_sorted(self): result = build_owned_card_list(["Sol Ring", "Command Tower", "Atraxa"]) assert result.index("Atraxa") < result.index("Command Tower") < result.index("Sol Ring") def test_format(self): result = build_owned_card_list(["Sol Ring"]) assert "OWNED CARDS:" in result assert "- Sol Ring" in result