65 lines
2 KiB
Python
65 lines
2 KiB
Python
from app.services.handoff_evaluator import ALL_MAIL_LABEL, ALL_TYPES_ID, evaluate_handoff
|
|
|
|
|
|
def test_handoff_requires_all_selected_filters():
|
|
email = {
|
|
"subject": "Payment approval required",
|
|
"snippet": "Please approve this invoice payment today.",
|
|
"body_text": "We need your approval for payment of $4,500.",
|
|
}
|
|
result = evaluate_handoff(
|
|
email=email,
|
|
labels=["Important", "Finance"],
|
|
email_types=["transactional"],
|
|
instructions="Forward when approval is required.",
|
|
)
|
|
assert result["would_handoff"] is True
|
|
assert result["label_matched"] is True
|
|
assert result["type_matched"] is True
|
|
|
|
|
|
def test_handoff_does_not_match_unrelated_instruction():
|
|
email = {
|
|
"subject": "Team lunch",
|
|
"snippet": "Where should we eat tomorrow?",
|
|
"body_text": "Let me know your preference.",
|
|
}
|
|
result = evaluate_handoff(
|
|
email=email,
|
|
labels=[],
|
|
email_types=[],
|
|
instructions="Forward when a refund requires approval.",
|
|
)
|
|
assert result["would_handoff"] is False
|
|
|
|
|
|
def test_handoff_all_mail_matches_generic_inbound():
|
|
email = {
|
|
"subject": "test handoff",
|
|
"snippet": "did you receive this?",
|
|
"body_text": "did you receive this?",
|
|
}
|
|
result = evaluate_handoff(
|
|
email=email,
|
|
labels=[ALL_MAIL_LABEL],
|
|
email_types=[ALL_TYPES_ID],
|
|
instructions="",
|
|
)
|
|
assert result["would_handoff"] is True
|
|
assert result["label_matched"] is True
|
|
assert result["type_matched"] is True
|
|
|
|
|
|
def test_handoff_selected_categories_do_not_match_generic_email():
|
|
email = {
|
|
"subject": "hi",
|
|
"snippet": "check the inbox please",
|
|
"body_text": "check the inbox please",
|
|
}
|
|
result = evaluate_handoff(
|
|
email=email,
|
|
labels=["Important", "Finance", "Clients"],
|
|
email_types=["transactional"],
|
|
instructions="",
|
|
)
|
|
assert result["would_handoff"] is False
|