80 lines
2.3 KiB
Python
80 lines
2.3 KiB
Python
from bson import ObjectId
|
|
|
|
from app.services.handoff_mirror_policy import (
|
|
GENERATED_BY_AGENT,
|
|
GENERATED_BY_CUSTOMER,
|
|
GENERATED_BY_HANDOFF_BRIDGE,
|
|
GENERATED_BY_RELAY_ACK,
|
|
MESSAGE_ORIGIN_EXTERNAL_CUSTOMER,
|
|
MESSAGE_ORIGIN_HUMAN_OWNER,
|
|
MESSAGE_ORIGIN_AGENT,
|
|
is_relay_acknowledgment_message,
|
|
should_mirror_to_human,
|
|
)
|
|
|
|
|
|
def test_should_mirror_customer_inbound():
|
|
message = {
|
|
"message_scope": "EXTERNAL",
|
|
"direction": "inbound",
|
|
"generated_by": GENERATED_BY_CUSTOMER,
|
|
"message_origin": MESSAGE_ORIGIN_EXTERNAL_CUSTOMER,
|
|
}
|
|
assert should_mirror_to_human(message) is True
|
|
|
|
|
|
def test_should_not_mirror_handoff_bridge_outbound():
|
|
message = {
|
|
"message_scope": "EXTERNAL",
|
|
"direction": "outbound",
|
|
"generated_by": GENERATED_BY_HANDOFF_BRIDGE,
|
|
"generated_from_handoff_message_id": ObjectId(),
|
|
}
|
|
assert should_mirror_to_human(message) is False
|
|
|
|
|
|
def test_should_not_mirror_human_origin():
|
|
message = {
|
|
"message_scope": "EXTERNAL",
|
|
"direction": "inbound",
|
|
"message_origin": MESSAGE_ORIGIN_HUMAN_OWNER,
|
|
}
|
|
assert should_mirror_to_human(message) is False
|
|
|
|
|
|
def test_should_mirror_agent_authored_external_reply():
|
|
message = {
|
|
"message_scope": "EXTERNAL",
|
|
"direction": "outbound",
|
|
"generated_by": GENERATED_BY_AGENT,
|
|
"message_origin": MESSAGE_ORIGIN_AGENT,
|
|
}
|
|
assert should_mirror_to_human(message) is True
|
|
|
|
|
|
def test_should_not_echo_human_relay_back_to_owner():
|
|
message = {
|
|
"message_scope": "EXTERNAL",
|
|
"direction": "outbound",
|
|
"generated_by": GENERATED_BY_HANDOFF_BRIDGE,
|
|
"message_origin": MESSAGE_ORIGIN_HUMAN_OWNER,
|
|
"generated_from_handoff_message_id": ObjectId(),
|
|
}
|
|
assert should_mirror_to_human(message) is False
|
|
|
|
|
|
def test_is_relay_acknowledgment_detects_legacy_body():
|
|
message = {
|
|
"direction": "outbound",
|
|
"body_text": "Sent to customer:\n\nhuman said B",
|
|
}
|
|
assert is_relay_acknowledgment_message(message) is True
|
|
|
|
|
|
def test_is_relay_acknowledgment_detects_generated_by():
|
|
message = {
|
|
"direction": "outbound",
|
|
"generated_by": GENERATED_BY_RELAY_ACK,
|
|
"body_text": "anything",
|
|
}
|
|
assert is_relay_acknowledgment_message(message) is True
|