feat(안내문 발송): DM 수동 보내기 — 이름 지우기·본문 편집·저장한 본문 목록
- 이름 목록: × 한 명씩 빼기·[전체 삭제], 이름 넣기는 목록에 더함
- 본문: 바로 고침(plaintext-only), {이름} 자리 = 분홍 칩, 이름 누르면 고친 글 + 이름 복사
- 저장한 본문(본문 오른쪽): 설정 DM 문구 + 저장한 것, 고르기·[저장]·[새 본문으로 저장]·× 지우기
- outreach_db 마이그레이션 002 outreach_dm_bodies + POST/PUT/DELETE /outreach/api/dm-bodies
(002 미적용이면 목록 안내만, API 503)
- 캐시 버전 20261030c, 단위·API·실제 PG·브라우저 테스트
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ function check(name, cond, extra) {
|
||||
const exe = process.env.PJ_TEST_BROWSER;
|
||||
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
|
||||
const calls = [];
|
||||
let dmBodies = [], dmSeq = 0; // 저장한 DM 본문(가짜 서버)
|
||||
try {
|
||||
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 }, permissions: ["clipboard-read", "clipboard-write"] });
|
||||
await ctx.route("**/*", function (r) {
|
||||
@@ -43,6 +44,15 @@ function check(name, cond, extra) {
|
||||
}
|
||||
if (url === "/outreach/api/recipients" && req.method() === "POST") return json({ ok: true, added: 2, existed: 0, invalid: 1 });
|
||||
if (url === "/outreach/api/send") return json({ ok: true, queued: body.ids.length }, 202);
|
||||
const dmb = /^\/outreach\/api\/dm-bodies(?:\/(\d+))?$/.exec(url);
|
||||
if (dmb) { // 저장한 DM 본문 — 새로 저장·고치기·지우기(제목 = 첫 줄)
|
||||
const title = function (b) { return b.split("\n").map(function (x) { return x.trim(); }).filter(Boolean)[0] || ""; };
|
||||
let id = dmb[1] ? +dmb[1] : 0;
|
||||
if (req.method() === "POST") { id = ++dmSeq; dmBodies.unshift({ id: id, title: title(body.body), body: body.body, updated_by: "me", updated_at: "" }); }
|
||||
if (req.method() === "PUT") { const b = dmBodies.find(function (x) { return x.id === id; }); b.body = body.body; b.title = title(body.body); }
|
||||
if (req.method() === "DELETE") dmBodies = dmBodies.filter(function (x) { return x.id !== id; });
|
||||
return json({ id: id, items: dmBodies });
|
||||
}
|
||||
if (url === "/outreach/api/recipients/1/preview") {
|
||||
return json({ subject: "누적매출 300억", html: "<p>안녕하세요, 김철수님.</p>", text: "안녕하세요, 김철수님.", kind: "email", to: "kim@miras.co.kr", sender_name: "미라네주방" });
|
||||
}
|
||||
@@ -155,6 +165,47 @@ function check(name, cond, extra) {
|
||||
dm.clip === dm.body && /박서준 님 문구를 클립보드에 복사/.test(dm.toast), dm);
|
||||
await p.waitForTimeout(1800);
|
||||
check("안내는 잠깐 뒤 사라짐", await p.evaluate(function () { return document.getElementById("otr-toast").hidden; }));
|
||||
// 이름 한 명 빼기(×) — 고른 사람(박서준)은 그대로 골라짐
|
||||
await p.click('#otr-dm-names [data-del="0"]');
|
||||
let st = await p.evaluate(function () {
|
||||
return { names: Array.from(document.querySelectorAll("#otr-dm-names .otr-dm-name")).map(function (e) { return e.textContent; }),
|
||||
active: (document.querySelector("#otr-dm-names .is-active") || {}).textContent, sum: document.getElementById("otr-dm-sum").textContent };
|
||||
});
|
||||
check("이름 한 명 빼기(×) — 고른 사람은 그대로", JSON.stringify(st.names) === '["박서준"]' && st.active === "박서준" && st.sum === "1명", st);
|
||||
// 본문 고치기 — 맨 앞에 글을 더 쓰고 이름을 다시 누르면 고친 글 + 이름이 복사
|
||||
await p.click("#otr-dm-body");
|
||||
await p.keyboard.press("Control+Home");
|
||||
await p.keyboard.type("추가 인사");
|
||||
await p.keyboard.press("Enter"); // 줄바꿈도 글(\n)로
|
||||
await p.click('#otr-dm-names .otr-dm-name[data-i="0"]');
|
||||
await p.waitForTimeout(100);
|
||||
st = await p.evaluate(function () {
|
||||
return { clip: window.__copied || "", tags: Array.from(document.querySelectorAll("#otr-dm-body .otr-dm-tag")).map(function (e) { return e.textContent; }) };
|
||||
});
|
||||
check("본문 고친 글 그대로(줄바꿈 포함) + 이름 칩(분홍) — 복사도 고친 글", /^추가 인사\n안녕/.test(st.clip) && st.clip.includes("박서준") && !st.clip.includes("{이름}") &&
|
||||
st.tags.length > 0 && st.tags.every(function (t) { return t === "박서준"; }), st);
|
||||
// 새 본문으로 저장 → 오른쪽 목록, 설정 DM 문구 ↔ 저장 본문 고르기, 하나씩 지우기
|
||||
await p.click("#otr-dm-saveas");
|
||||
await p.waitForTimeout(150);
|
||||
const saved = calls.filter(function (c) { return c.url === "/outreach/api/dm-bodies" && c.method === "POST"; }).pop();
|
||||
st = await p.evaluate(function () {
|
||||
return { items: Array.from(document.querySelectorAll("#otr-dm-bodies .otr-dm-name")).map(function (e) { return e.textContent.trim(); }),
|
||||
cur: document.getElementById("otr-dm-cur").textContent, save: !document.getElementById("otr-dm-save").disabled };
|
||||
});
|
||||
check("새 본문으로 저장 — {이름} 자리는 {이름} 으로 저장, 목록에 첫 줄 제목", !!saved && /^추가 인사\n/.test(saved.body.body) && saved.body.body.includes("{이름}") &&
|
||||
!saved.body.body.includes("박서준") && st.items.length === 2 && /^추가 인사/.test(st.items[1]) && /추가 인사/.test(st.cur) && st.save, { saved: saved, st: st });
|
||||
await p.click('#otr-dm-bodies [data-body="settings"]');
|
||||
const back = await p.evaluate(function () { return document.getElementById("otr-dm-body").textContent; });
|
||||
await p.click('#otr-dm-bodies [data-body="1"]');
|
||||
const again = await p.evaluate(function () { return document.getElementById("otr-dm-body").textContent; });
|
||||
check("목록에서 본문 고르기 — 설정 DM 문구 ↔ 저장한 본문", !/^추가 인사/.test(back) && /^추가 인사\n?안녕/.test(again), { back: back.slice(0, 20), again: again.slice(0, 20) });
|
||||
await p.click('#otr-dm-bodies [data-delbody="1"]');
|
||||
await p.waitForTimeout(150);
|
||||
st = await p.evaluate(function () { return document.querySelectorAll("#otr-dm-bodies .otr-dm-name").length; });
|
||||
check("저장한 본문 하나 지우기(×)", st === 1 && calls.some(function (c) { return c.method === "DELETE" && c.url === "/outreach/api/dm-bodies/1"; }), st);
|
||||
await p.click("#otr-dm-clear");
|
||||
st = await p.evaluate(function () { return { n: document.querySelectorAll("#otr-dm-names .otr-dm-name").length, tag: document.querySelector("#otr-dm-body .otr-dm-tag").textContent }; });
|
||||
check("이름 전체 삭제 — 본문은 {이름} 으로", st.n === 0 && st.tag === "{이름}", st);
|
||||
await p.goBack();
|
||||
await p.waitForSelector("#otr-add-open");
|
||||
// 리스트 추가 — 미리보기(판별) → 추가
|
||||
|
||||
@@ -42,7 +42,8 @@ def main() -> None:
|
||||
f.write(env.get_template("outreach/index.html").render(**ctx))
|
||||
# DM 수동 보내기 탭(2026-10-30)
|
||||
with open(os.path.join(OUT_DIR, "outreach_dm.html"), "w", encoding="utf-8") as f:
|
||||
f.write(env.get_template("outreach/dm.html").render(**{**ctx, "active_tab": "dm", "dm_template": store.dm_text(t, store.NAME_TAG)}))
|
||||
f.write(env.get_template("outreach/dm.html").render(**{**ctx, "active_tab": "dm", "dm_template": store.dm_text(t, store.NAME_TAG),
|
||||
"dm_bodies": [], "dm_max": store.DM_MAX}))
|
||||
# 설정 화면 — 저장해 둔 서식 본문(HTML)·DM 문구로
|
||||
saved = store.normalize_template({
|
||||
"subject": "{이름}님께 제안", "fmt": "html", "dm_body": "안녕하세요 {이름}님, DM 입니다",
|
||||
|
||||
+49
-1
@@ -235,6 +235,17 @@ class Store:
|
||||
self.t = t; self.saved = by; return self.get_template()
|
||||
def list_images(self, with_data=False): return []
|
||||
def list_logs(self, limit=200): return []
|
||||
dm_bodies = []
|
||||
def list_dm_bodies(self): return [dict(b) for b in reversed(self.dm_bodies)]
|
||||
def save_dm_body(self, body, by, body_id=None):
|
||||
title, text = ostore.dm_saved_body(body)
|
||||
if body_id is None:
|
||||
self.seq += 1; self.dm_bodies.append({"id": self.seq, "title": title, "body": text, "created_by": by, "updated_by": by, "updated_at": ""})
|
||||
return self.seq
|
||||
b = next((x for x in self.dm_bodies if x["id"] == body_id), None)
|
||||
if b is None: raise KeyError(body_id)
|
||||
b.update(title=title, body=text, updated_by=by); return body_id
|
||||
def delete_dm_body(self, body_id): self.dm_bodies = [b for b in self.dm_bodies if b["id"] != body_id]
|
||||
def list_recipients(self): return [dict(r) for r in self.rows]
|
||||
def get_recipient(self, rid): return next((dict(r) for r in self.rows if r["id"] == rid), None)
|
||||
def add_recipients(self, rows, by):
|
||||
@@ -360,7 +371,17 @@ def body(c):
|
||||
# DM 수동 보내기 탭(2026-10-30) — {이름} 을 그대로 둔 DM 문구(별표 뺌)를 화면 데이터로
|
||||
d = c.get("/outreach/dm").text
|
||||
dm_data = __import__("json").loads(d.split('id="otr-data">')[1].split("</script>")[0])
|
||||
assert 'id="otr-dm-names"' in d and "DM 수동 보내기" in d and dm_data == {"dm_template": "{이름}님, DM 문구입니다"}, dm_data
|
||||
assert 'id="otr-dm-names"' in d and "DM 수동 보내기" in d and dm_data == {"dm_template": "{이름}님, DM 문구입니다",
|
||||
"dm_bodies": [], "dm_max": 1000}, dm_data
|
||||
# 저장한 본문 — 새로 저장(제목 = 첫 줄)·고치기·없는 것 404·빈 글/너무 김 400·지우기
|
||||
r = c.post("/outreach/api/dm-bodies", json={"body": "\\n 첫 줄 제목\\n{이름}님 안녕하세요"})
|
||||
assert r.status_code == 200 and r.json()["items"][0]["title"] == "첫 줄 제목", r.text
|
||||
bid = r.json()["id"]
|
||||
assert c.put(f"/outreach/api/dm-bodies/{bid}", json={"body": "바꾼 제목\\n본문"}).json()["items"][0]["body"] == "바꾼 제목\\n본문"
|
||||
assert c.put("/outreach/api/dm-bodies/99999", json={"body": "x"}).status_code == 404
|
||||
assert c.post("/outreach/api/dm-bodies", json={"body": " "}).status_code == 400
|
||||
assert c.post("/outreach/api/dm-bodies", json={"body": "가" * 1001}).status_code == 400
|
||||
assert c.delete(f"/outreach/api/dm-bodies/{bid}").json()["items"] == []
|
||||
# 서식 편집기 본문(fmt=html) — 서버가 정리해 저장, 메일 미리보기에 서식·이름
|
||||
r = c.post("/outreach/settings", data={"subject": "{이름}님 제안", "fmt": "html", "dm_body": "",
|
||||
"body": '<p>안녕 <span style="color: rgb(230, 0, 0)" onclick="x">{이름}</span>님</p><script>x</script>'})
|
||||
@@ -431,6 +452,17 @@ run(body)
|
||||
self.assertIn("OK", res.stdout)
|
||||
|
||||
|
||||
class DmSavedBodyTests(unittest.TestCase):
|
||||
def test_title_is_first_line_and_limits(self):
|
||||
from app.modules.outreach import store as ostore
|
||||
|
||||
self.assertEqual(ostore.dm_saved_body("\r\n\n 안녕 {이름}님 \r\n둘째"), ("안녕 {이름}님", "안녕 {이름}님 \n둘째"))
|
||||
self.assertEqual(ostore.dm_saved_body("가" * 50)[0], "가" * 40 + "…")
|
||||
for bad in ("", " \n ", "가" * (ostore.DM_MAX + 1)):
|
||||
with self.assertRaises(ValueError):
|
||||
ostore.dm_saved_body(bad)
|
||||
|
||||
|
||||
@unittest.skipUnless(DB_ENABLED, "OUTREACH_TEST_DB_URL(localhost) 미설정")
|
||||
class OutreachDBTests(unittest.TestCase):
|
||||
@classmethod
|
||||
@@ -443,6 +475,22 @@ class OutreachDBTests(unittest.TestCase):
|
||||
def tearDownClass(cls):
|
||||
cls.st.close()
|
||||
|
||||
def test_dm_bodies(self):
|
||||
st = self.st
|
||||
tag = uuid.uuid4().hex[:6]
|
||||
a = st.save_dm_body(f"제목{tag}\n{{이름}}님", by="Me@X.com")
|
||||
b = st.save_dm_body(f"둘째{tag}", by="me@x.com")
|
||||
items = [x for x in st.list_dm_bodies() if tag in x["title"]]
|
||||
self.assertEqual([x["id"] for x in items], [b, a]) # 새로 고친 것부터
|
||||
self.assertEqual((items[1]["body"], items[1]["created_by"]), (f"제목{tag}\n{{이름}}님", "me@x.com"))
|
||||
st.save_dm_body(f"고침{tag}", by="me@x.com", body_id=a)
|
||||
self.assertEqual([x["title"] for x in st.list_dm_bodies() if tag in x["title"]][0], f"고침{tag}")
|
||||
with self.assertRaises(KeyError):
|
||||
st.save_dm_body("x", by="me@x.com", body_id=-1)
|
||||
st.delete_dm_body(a)
|
||||
st.delete_dm_body(b)
|
||||
self.assertFalse([x for x in st.list_dm_bodies() if tag in x["title"]])
|
||||
|
||||
def test_recipients_claim_finish_logs(self):
|
||||
import threading
|
||||
|
||||
|
||||
Reference in New Issue
Block a user