You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
# backend/tests/test_api_mail.py
|
|
def _flatten_titles(nodes):
|
|
out = []
|
|
for n in nodes:
|
|
out.append(n["title"])
|
|
out += _flatten_titles(n.get("children", []))
|
|
return out
|
|
|
|
|
|
def test_list_accounts(client):
|
|
r = client.get("/api/mail/accounts")
|
|
assert [a["id"] for a in r.json()] == ["work", "personal", "side"]
|
|
assert r.json()[0]["tone"] == "coral"
|
|
|
|
|
|
def test_list_mail_count(client):
|
|
rows = client.get("/api/mail").json()
|
|
assert len(rows) == 8
|
|
assert rows[0]["from"] == "hyunwoo" # alias
|
|
|
|
|
|
def test_email_detail_marks_read(client):
|
|
assert client.get("/api/mail/m1").json()["read"] is True
|
|
assert client.get("/api/mail/m1").json()["from"] == "hyunwoo"
|
|
|
|
|
|
def test_extract_task_creates_task(client):
|
|
r = client.post("/api/mail/m1/extract", json={"kind": "task", "index": 0})
|
|
body = r.json()
|
|
assert body["kind"] == "task"
|
|
assert body["task"]["project_id"] == "onb-wire"
|
|
assert body["task"]["prio"] == "높음"
|
|
assert "온보딩 시안 v3 피드백 정리" in _flatten_titles(client.get("/api/tasks").json())
|
|
|
|
|
|
def test_extract_event_creates_event(client):
|
|
r = client.post("/api/mail/m2/extract", json={"kind": "event", "index": 0})
|
|
assert r.json()["kind"] == "event" and r.json()["event_id"]
|
|
|
|
|
|
def test_extract_all(client):
|
|
r = client.post("/api/mail/m1/extract-all", json={})
|
|
assert len(r.json()["created_task_ids"]) == 2
|
|
assert r.json()["filed_project"] == "온보딩 리디자인"
|
|
|
|
|
|
def test_reply_draft_picks_seeded(client):
|
|
r = client.post("/api/mail/m1/reply-draft", json={"reply_index": 0})
|
|
assert r.json()["subject"].startswith("Re: ")
|
|
assert "금요일" in r.json()["body"]
|
|
|
|
|
|
def test_send_creates_high_risk_approval(client):
|
|
r = client.post(
|
|
"/api/mail/send",
|
|
json={
|
|
"from_account": "work",
|
|
"to": "현우 <hyunwoo@lumi.co>",
|
|
"subject": "Re: 온보딩",
|
|
"body": "확인했어요",
|
|
},
|
|
)
|
|
assert r.json()["status"] == "pending"
|
|
appr = client.get(f"/api/approvals/{r.json()['approval_id']}").json()
|
|
assert appr["risk"] == "high" and appr["source"] == "mail"
|
|
|
|
|
|
def test_m7_empty_ai(client):
|
|
ai = client.get("/api/mail/m7").json()["ai"]
|
|
assert ai["priority"] == "낮음" and ai["tasks"] == [] and ai["events"] == []
|
|
|
|
|
|
def test_extract_404(client):
|
|
assert client.post("/api/mail/nope/extract", json={"kind": "task"}).status_code == 404
|
|
|
|
|
|
def test_account_filter(client):
|
|
rows = client.get("/api/mail?account=side").json()
|
|
assert all(r["account"] == "side" for r in rows) and len(rows) == 1 # m5
|