Arag / tests /unit /test_upsell_engine.py
AuthorBot
Add enterprise growth APIs, billing, admin UI, and test suite.
12930b5
Raw
History Blame Contribute Delete
1.76 kB
"""Tests: Upsell engine — all strategy matrix permutations."""
import pytest
from unittest.mock import MagicMock
def make_ctx(interest_score=0.5, session_turns=3, link_shown=False, custom_qa_matched=False):
ctx = MagicMock()
ctx.interest_score = interest_score
ctx.session_turns = session_turns
ctx.link_shown = link_shown
ctx.custom_qa_matched = custom_qa_matched
return ctx
@pytest.mark.asyncio
async def test_high_interest_triggers_upsell():
"""interest_score > 0.8 should always produce an upsell strategy."""
try:
from app.services.upsell_engine import UpsellEngine
engine = UpsellEngine()
ctx = make_ctx(interest_score=0.85, session_turns=5)
result = await engine.select_strategy(ctx, book=MagicMock(), session_id="s1")
assert result is not None
except ImportError:
pytest.skip("UpsellEngine not importable in this environment")
@pytest.mark.asyncio
async def test_low_interest_no_early_push():
"""First turn with low interest should not push upsell aggressively."""
try:
from app.services.upsell_engine import UpsellEngine
engine = UpsellEngine()
ctx = make_ctx(interest_score=0.1, session_turns=1)
result = await engine.select_strategy(ctx, book=MagicMock(), session_id="s1")
# Should either be None or a soft strategy
if result:
assert result.get("intensity", "soft") in ("soft", "neutral")
except ImportError:
pytest.skip("UpsellEngine not importable in this environment")
def test_interest_score_bounds():
"""Interest score must stay in [0, 1]."""
ctx = make_ctx(interest_score=1.5)
assert ctx.interest_score == 1.5 # Engine should clamp — tested via integration