File size: 2,202 Bytes
bf6dbfa
 
 
 
 
 
0643073
bf6dbfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0643073
bf6dbfa
 
 
 
0643073
bf6dbfa
 
 
 
 
 
 
 
0643073
bf6dbfa
 
 
 
0643073
bf6dbfa
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pytest
from agent.nodes import process_lead, LeadExtractionResponse
from agent.state import AgentState
from langchain_core.runnables import RunnableLambda

def test_lead_workflow_step_by_step(mocker):

    state = AgentState(
        conversation_history=[],
        current_message="I want the Pro plan for my YouTube channel",
        detected_intent="HIGH_INTENT_LEAD",
        retrieved_documents=[],
        user_name=None,
        user_email=None,
        creator_platform=None,
        lead_ready=False,
        response=""
    )

    mock_llm = mocker.MagicMock()
    mock_chain_1 = RunnableLambda(lambda x: LeadExtractionResponse(user_name=None, user_email=None, creator_platform="YouTube"))
    mock_llm.with_structured_output.return_value = mock_chain_1
    mocker.patch('agent.nodes.get_llm', return_value=mock_llm)

    result = process_lead(state)
    assert result.get("user_name") is None
    assert result.get("creator_platform") == "YouTube"
    assert "name" in result["response"].lower()


    state.update(result)
    state["conversation_history"].append({"role": "user", "content": state["current_message"]})
    state["conversation_history"].append({"role": "assistant", "content": state["response"]})


    state["current_message"] = "My name is Alex"
    mock_chain_2 = RunnableLambda(lambda x: LeadExtractionResponse(user_name="Alex", user_email=None, creator_platform=None))
    mock_llm.with_structured_output.return_value = mock_chain_2

    result = process_lead(state)
    assert result.get("user_name") == "Alex"
    assert "email" in result["response"].lower()


    state.update(result)
    state["conversation_history"].append({"role": "user", "content": state["current_message"]})
    state["conversation_history"].append({"role": "assistant", "content": state["response"]})


    state["current_message"] = "alex@email.com"
    mock_chain_3 = RunnableLambda(lambda x: LeadExtractionResponse(user_name=None, user_email="alex@email.com", creator_platform=None))
    mock_llm.with_structured_output.return_value = mock_chain_3

    result = process_lead(state)
    assert result.get("user_email") == "alex@email.com"
    assert result.get("lead_ready") is True