from app.services.handoff_email_templates import ( build_mirror_handoff_html, build_mirror_handoff_text, external_reply_subject, format_sender_line, handoff_email_subject, ) from app.services.html_sanitizer import sanitize_email_html from app.services.mime_body_extractor import extract_mirror_content from app.services.thread_service import threading_fields_from_parent def test_mirror_template_is_minimal(): html = build_mirror_handoff_html( sender_line="091rabbytes@gmail.com", external_subject="lets try one more time", original_html="

one last attempt. i am tired

", agent_email="suyash@gentic.email", ) assert "LATEST MESSAGE" not in html assert "Why you" not in html assert "gentic-handoff-original" in html assert "one last attempt. i am tired" in html assert "✦ Human Handoff" in html assert "091rabbytes@gmail.com" in html assert "lets try one more time" in html def test_mirror_plain_text_template(): text = build_mirror_handoff_text( sender_line="091rabbytes@gmail.com", external_subject="lets try one more time", original_body_text="one last attempt. i am tired", agent_email="suyash@gentic.email", ) assert "one last attempt. i am tired" in text assert "LATEST MESSAGE" not in text assert "Reply normally" in text def test_format_sender_with_name(): assert ( format_sender_line({"name": "Rahul Sharma", "address": "rahul@example.com"}) == "Rahul Sharma " ) def test_external_threading_headers_from_customer_message(): parent = { "_id": "mongo-id", "message_id": "", "references": [], } threading = threading_fields_from_parent(parent) assert threading["in_reply_to"] == "" assert threading["references"] == [""] def test_external_reply_subject_uses_customer_subject(): assert external_reply_subject("lets try one more time") == "Re: lets try one more time" assert handoff_email_subject("lets try one more time") == "Human Handoff · lets try one more time" def test_sanitize_removes_script(): dirty = '

Hello

' clean = sanitize_email_html(dirty) assert "Invoice
Amount
\r\n" b"--b--\r\n" ) extracted = extract_mirror_content(raw) assert "Invoice" in (extracted.body_html or "") assert "" in (extracted.body_html or "")