import pytest from agent.nodes import detect_intent from agent.state import AgentState from agent.nodes import IntentResponse from langchain_core.runnables import RunnableLambda def test_intent_classifier_greeting(mocker): state = AgentState( conversation_history=[], current_message="Hi there", detected_intent=None, retrieved_documents=[], user_name=None, user_email=None, creator_platform=None, lead_ready=False, response="" ) mock_llm = mocker.MagicMock() mock_chain = RunnableLambda(lambda x: IntentResponse(intent="GREETING", confidence=0.99)) mock_llm.with_structured_output.return_value = mock_chain mocker.patch('agent.nodes.get_llm', return_value=mock_llm) result = detect_intent(state) assert result["detected_intent"] == "GREETING" def test_intent_classifier_pricing(mocker): state = AgentState( conversation_history=[], current_message="What are your pricing plans?", detected_intent=None, retrieved_documents=[], user_name=None, user_email=None, creator_platform=None, lead_ready=False, response="" ) mock_llm = mocker.MagicMock() mock_chain = RunnableLambda(lambda x: IntentResponse(intent="PRICING_QUERY", confidence=0.95)) mock_llm.with_structured_output.return_value = mock_chain mocker.patch('agent.nodes.get_llm', return_value=mock_llm) result = detect_intent(state) assert result["detected_intent"] == "PRICING_QUERY" def test_intent_classifier_high_intent(mocker): state = AgentState( conversation_history=[], current_message="I want to sign up for Pro plan", detected_intent=None, retrieved_documents=[], user_name=None, user_email=None, creator_platform=None, lead_ready=False, response="" ) mock_llm = mocker.MagicMock() mock_chain = RunnableLambda(lambda x: IntentResponse(intent="HIGH_INTENT_LEAD", confidence=0.91)) mock_llm.with_structured_output.return_value = mock_chain mocker.patch('agent.nodes.get_llm', return_value=mock_llm) result = detect_intent(state) assert result["detected_intent"] == "HIGH_INTENT_LEAD"