aefb2aa119
Four bot-side UX fixes surfaced by the live smoke: - Post a brief pointer in the main timeline (a reply to the user's message) alongside the in-thread proposal card, so proposals aren't missed inside a thread. Pointer only — approvals still happen in the thread, where the note is visible (you can't make an informed yes/no without seeing it). - A bare yes/no typed in the main timeline while a proposal is pending now gets a "reply in the thread" redirect instead of "couldn't tell what to record." - Clearer commit confirmations: "Created a new grid entry for X" vs "Logged a note on X (existing grid entry)." - Send a blank communication subject when a note is present so the grid's one-line note summary shows the note text, not the "(Matrix)" label (provenance stays in source="matrix_intake").
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
"""Tests for the CRM client's payload builder (pure logic, no network)."""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
import crm_client # noqa: E402
|
|
|
|
|
|
def test_new_investor_payload():
|
|
p = {"intent": "new_investor", "investor_name": "Acme Capital",
|
|
"contact_name": "Jane Doe", "contact_email": "jane@acme.com",
|
|
"contact_title": "GP", "note": "met at conf"}
|
|
out = crm_client.build_commit_payload(p)
|
|
assert out["investor_name"] == "Acme Capital"
|
|
assert out["create_investor_if_missing"] is True
|
|
assert "row_id" not in out
|
|
assert out["contact"] == {"name": "Jane Doe", "email": "jane@acme.com", "title": "GP"}
|
|
assert out["body"] == "met at conf"
|
|
assert out["source"] == "matrix_intake"
|
|
|
|
|
|
def test_existing_investor_uses_row_id_not_create():
|
|
p = {"intent": "meeting_note", "investor_name": "Acme Capital",
|
|
"contact_name": "Jane Doe", "contact_email": None, "note": "wants Q3 deck",
|
|
"_match_id": "rowAcme"}
|
|
out = crm_client.build_commit_payload(p)
|
|
assert out["row_id"] == "rowAcme"
|
|
assert "create_investor_if_missing" not in out
|
|
assert "investor_name" not in out # targeted by row id, never re-matched by name
|
|
assert out["body"] == "wants Q3 deck"
|
|
|
|
|
|
def test_contact_falls_back_to_investor_name_when_no_person():
|
|
p = {"intent": "new_investor", "investor_name": "Delta Fund",
|
|
"contact_name": None, "contact_email": None, "note": None}
|
|
out = crm_client.build_commit_payload(p)
|
|
assert out["contact"]["name"] == "Delta Fund"
|
|
assert out["body"] == ""
|
|
|
|
|
|
def test_no_email_sends_empty_string_not_none():
|
|
p = {"intent": "new_investor", "investor_name": "Gamma", "contact_name": "Bob",
|
|
"contact_email": None, "note": "x"}
|
|
out = crm_client.build_commit_payload(p)
|
|
assert out["contact"]["email"] == ""
|
|
|
|
|
|
def test_subject_blank_when_note_present_else_provenance_label():
|
|
# The CRM's grid note line uses subject-or-body, so a blank subject lets the note text show.
|
|
with_note = crm_client.build_commit_payload(
|
|
{"intent": "meeting_note", "investor_name": "Acme", "note": "sent the deck", "_match_id": "r1"})
|
|
assert with_note["subject"] == ""
|
|
assert with_note["body"] == "sent the deck"
|
|
# no note text → fall back to a provenance label so the grid line isn't empty
|
|
no_note = crm_client.build_commit_payload(
|
|
{"intent": "new_investor", "investor_name": "Beta", "contact_name": "X", "note": None})
|
|
assert no_note["subject"] == "Intake (Matrix)"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_") and callable(v)]
|
|
for fn in fns:
|
|
fn()
|
|
print(f"ok {fn.__name__}")
|
|
print(f"\n{len(fns)} passed")
|