8c805fdd9c
- 새 모듈 app/modules/outreach(권한키 outreach, outreach_db — scripts/sql/outreach_db_init.sql, OUTREACH_DB_URL)
- 리스트 붙여넣기(주소, 이름) → 주소를 보고 메일/DM 판별(store.detect: 이메일·@계정·instagram.com·ig.me·계정명) → 미리보기 → 추가
- 메일 = 고른 줄을 한 UPDATE 로 발송중(두 번 눌러도 한 번) → 백그라운드로 본인 Gmail 한 사람에 한 통(입출고·휴가와 같은 Gmail 연결),
설정 사진 본문 아래(cid), 보냄/실패·기록. 인스타 = 이름 넣은 문구 복사 + ig.me DM 창 → [보냄] 기록(공식 API 는 첫 DM 불가)
- 설정: 제목·본문 기본 = 미라네주방 공동구매 제안 문구, {이름}·**굵게**, 보내는 이름·끝 문구·(광고) 표시, 사진 10장
- 입출고 Gmail 콜백을 모듈 공용으로(_GMAIL_ORIGINS — vacation·outreach)
- 테스트: 판별·본문·발송(가짜 Gmail)·실제 앱·실제 PG(동시 claim 4번 = 1번)·브라우저
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
146 lines
10 KiB
JavaScript
146 lines
10 KiB
JavaScript
// 안내문 발송 리스트 화면(2026-10-27) — 실제 브라우저(Chromium).
|
|
// python tests/js/render_outreach.py
|
|
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/outreach.browser.test.js
|
|
// 구분 배지(메일/DM)·걸러 보기, [DM 보내기] = 그 사람 이름이 든 문구 복사 + ig.me DM 창 새 탭, [보냄] 기록, 이름 없는 줄 표시,
|
|
// 붙여넣기 미리보기(메일/DM/오류) → 추가, 고른 메일 보내기(메일 줄만, 확인 창), 미리보기 창. 서버 API 는 테스트 안 가짜.
|
|
const fs = require("fs"), path = require("path");
|
|
const { chromium } = require("playwright");
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
const fails = [];
|
|
function check(name, cond, extra) {
|
|
if (cond) console.log("PASS " + name);
|
|
else { console.log("FAIL " + name + (extra !== undefined ? " → " + JSON.stringify(extra) : "")); fails.push(name); }
|
|
}
|
|
|
|
(async function () {
|
|
const exe = process.env.PJ_TEST_BROWSER;
|
|
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
|
|
const calls = [];
|
|
try {
|
|
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 }, permissions: ["clipboard-read", "clipboard-write"] });
|
|
await ctx.route("**/*", function (r) {
|
|
const req = r.request(), u = new URL(req.url()), url = u.pathname;
|
|
if (u.host === "ig.me") return r.fulfill({ status: 200, contentType: "text/html", body: "<title>ig</title>" });
|
|
if (url.startsWith("/static/")) {
|
|
const f = path.join(ROOT, "app", url);
|
|
if (!fs.existsSync(f)) return r.fulfill({ status: 404, body: "" });
|
|
return r.fulfill({ status: 200, contentType: f.endsWith(".css") ? "text/css" : "application/javascript", body: fs.readFileSync(f) });
|
|
}
|
|
if (url.startsWith("/outreach/api/")) {
|
|
const body = req.postData() ? JSON.parse(req.postData()) : null;
|
|
calls.push({ method: req.method(), url: url, body: body });
|
|
const json = function (o, s) { return r.fulfill({ status: s || 200, contentType: "application/json", body: JSON.stringify(o) }); };
|
|
if (url === "/outreach/api/recipients/2/dm-sent") {
|
|
return json({ row: { id: 2, kind: "instagram", kind_label: "DM", handle: "mira.kitchen", address: "@mira.kitchen", name: "미라",
|
|
status: "보냄", sent_at: "2026-10-27T11:00:00+09:00", sent_via: "dm", dm_link: "https://ig.me/m/mira.kitchen",
|
|
profile_link: "https://www.instagram.com/mira.kitchen/", dm_text: "x", needs_name: false, last_error: "" } });
|
|
}
|
|
if (url === "/outreach/api/recipients/parse") {
|
|
return json({ rows: [
|
|
{ line: 1, address: "new@x.com", name: "새사람", kind: "email", kind_label: "메일", handle: "new@x.com", error: "", dup: false, exists: false },
|
|
{ line: 2, address: "@hong", name: "홍", kind: "instagram", kind_label: "DM", handle: "hong", error: "", dup: false, exists: false },
|
|
{ line: 3, address: "홍길동", name: "", kind: null, kind_label: "오류", handle: "", error: "이메일도 인스타그램 주소도 아닙니다: 홍길동", dup: false, exists: false }] });
|
|
}
|
|
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);
|
|
if (url === "/outreach/api/recipients/1/preview") {
|
|
return json({ subject: "누적매출 300억", html: "<p>안녕하세요, 김철수님.</p>", text: "안녕하세요, 김철수님.", kind: "email", to: "kim@miras.co.kr", sender_name: "미라네주방" });
|
|
}
|
|
if (url === "/outreach/api/recipients" && req.method() === "GET") {
|
|
const data = JSON.parse(fs.readFileSync(path.join(__dirname, ".out", "outreach.html"), "utf8")
|
|
.match(/<script type="application\/json" id="otr-data">([\s\S]*?)<\/script>/)[1]);
|
|
return json(data);
|
|
}
|
|
return json({});
|
|
}
|
|
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: fs.readFileSync(path.join(__dirname, ".out", "outreach.html"), "utf8") });
|
|
});
|
|
const p = await ctx.newPage();
|
|
p.on("dialog", function (d) { d.accept(); });
|
|
// http 테스트 주소는 보안 컨텍스트가 아니라 navigator.clipboard 가 없다 → 화면이 쓰는 예비 복사(execCommand)를 잡아 본다
|
|
// (운영은 https 라 navigator.clipboard.writeText 로 복사)
|
|
await p.addInitScript(function () {
|
|
const orig = document.execCommand.bind(document);
|
|
document.execCommand = function (cmd) {
|
|
if (cmd === "copy") { const a = document.activeElement; window.__copied = a && "value" in a ? a.value : ""; return true; }
|
|
return orig.apply(document, arguments);
|
|
};
|
|
});
|
|
await p.goto("http://erp.test/outreach/");
|
|
await p.waitForTimeout(200);
|
|
const rowsInfo = function () {
|
|
return p.evaluate(function () {
|
|
return Array.from(document.querySelectorAll("#otr-tbody tr")).map(function (tr) {
|
|
return { id: +tr.dataset.id, kind: tr.querySelector(".otr-kind").textContent, name: tr.querySelector(".otr-name").value,
|
|
status: tr.querySelector(".otr-st").textContent, noname: tr.classList.contains("is-noname"),
|
|
acts: Array.from(tr.querySelectorAll("[data-act]")).map(function (b) { return b.dataset.act; }) };
|
|
});
|
|
});
|
|
};
|
|
const r0 = await rowsInfo();
|
|
check("구분 배지 = 주소를 보고 메일/DM, DM 줄은 [DM 보내기]·[보냄], 메일 줄은 [미리보기]",
|
|
JSON.stringify(r0.map(function (r) { return r.kind; })) === '["메일","DM","메일","메일"]' &&
|
|
JSON.stringify(r0[1].acts) === '["dm","dm-sent"]' && JSON.stringify(r0[0].acts) === '["preview"]', r0);
|
|
check("본문 {이름} 인데 이름 없는 줄 = 표시", r0[2].noname && !r0[0].noname, r0[2]);
|
|
const cnt = await p.evaluate(function () {
|
|
const o = {}; document.querySelectorAll("[data-cnt]").forEach(function (n) { o[n.dataset.cnt] = n.textContent; }); return o;
|
|
});
|
|
check("걸러 보기 개수", cnt.all === "4" && cnt.email === "3" && cnt.instagram === "1" && cnt["보냄"] === "1", cnt);
|
|
await p.click('[data-filter="instagram"]');
|
|
check("DM 만 보기", (await rowsInfo()).length === 1);
|
|
await p.click('[data-filter="all"]');
|
|
// DM 보내기 — 문구 복사 + DM 창
|
|
const [igPage] = await Promise.all([ctx.waitForEvent("page"), p.click('tr[data-id="2"] [data-act="dm"]')]);
|
|
await igPage.waitForLoadState().catch(function () {});
|
|
const clip = await p.evaluate(function () {
|
|
return navigator.clipboard ? navigator.clipboard.readText() : (window.__copied || "");
|
|
});
|
|
check("[DM 보내기] = ig.me/m/계정 새 탭", /ig\.me\/m\/mira\.kitchen/.test(igPage.url()), igPage.url());
|
|
check("[DM 보내기] = 이름이 들어간 DM 문구 복사(별표 없음)", clip.indexOf("안녕하세요, 미라님.") === 0 && clip.indexOf("**") < 0 &&
|
|
clip.indexOf("'미라네주방'입니다") > 0, clip.slice(0, 80));
|
|
await igPage.close();
|
|
await p.click('tr[data-id="2"] [data-act="dm-sent"]');
|
|
await p.waitForTimeout(100);
|
|
const r1 = await rowsInfo();
|
|
check("[보냄] → 보냄, 버튼 빠짐", r1[1].status === "보냄" && JSON.stringify(r1[1].acts) === '["dm"]' &&
|
|
calls.some(function (c) { return c.url === "/outreach/api/recipients/2/dm-sent"; }), r1[1]);
|
|
// 미리보기 창
|
|
await p.click('tr[data-id="1"] [data-act="preview"]');
|
|
await p.waitForTimeout(100);
|
|
const pv = await p.evaluate(function () {
|
|
return { shown: !document.getElementById("otr-preview").hidden, subject: document.getElementById("otr-pv-subject").textContent,
|
|
doc: document.getElementById("otr-pv-frame").srcdoc };
|
|
});
|
|
check("미리보기 창 = 제목·본문(그 사람 이름)", pv.shown && /누적매출 300억/.test(pv.subject) && /김철수님/.test(pv.doc), pv);
|
|
await p.keyboard.press("Escape");
|
|
// 고른 메일 보내기 — 전부 고르면 메일·대기만(1·3), DM·보냄 빠짐
|
|
await p.check("#otr-check-all");
|
|
check("고른 줄 수 표시", /고른 줄 4 · 보낼 메일 2/.test(await p.textContent("#otr-selected")), await p.textContent("#otr-selected"));
|
|
await p.click("#otr-send");
|
|
await p.waitForTimeout(200);
|
|
const sendCall = calls.find(function (c) { return c.url === "/outreach/api/send"; });
|
|
check("고른 메일 보내기 → 메일·대기 줄만 보냄", !!sendCall && JSON.stringify(sendCall.body.ids) === "[1,3]", sendCall);
|
|
// 리스트 추가 — 미리보기(판별) → 추가
|
|
await p.click("#otr-add-open");
|
|
await p.fill("#otr-add-text", "new@x.com 새사람\n@hong 홍\n홍길동");
|
|
check("미리보기 전엔 [리스트에 추가] 꺼짐", await p.isDisabled("#otr-add-save"));
|
|
await p.click("#otr-add-preview");
|
|
await p.waitForTimeout(100);
|
|
const prev = await p.evaluate(function () {
|
|
return { kinds: Array.from(document.querySelectorAll("#otr-add-result .otr-kind")).map(function (n) { return n.textContent; }),
|
|
sum: document.getElementById("otr-add-sum").textContent, err: document.querySelector("#otr-add-result .otr-err").textContent };
|
|
});
|
|
check("붙여넣기 미리보기 = 메일/DM/오류 + 요약", JSON.stringify(prev.kinds) === '["메일","DM","오류"]' &&
|
|
/새로 2명 \(메일 1 · DM 1\) · 오류 1줄/.test(prev.sum) && /인스타그램 주소도 아닙니다/.test(prev.err), prev);
|
|
await p.click("#otr-add-save");
|
|
await p.waitForTimeout(150);
|
|
const add = calls.find(function (c) { return c.method === "POST" && c.url === "/outreach/api/recipients"; });
|
|
check("[리스트에 추가] → 붙여 넣은 글 그대로 서버로, 창 닫힘", !!add && /new@x\.com 새사람/.test(add.body.text) &&
|
|
await p.evaluate(function () { return document.getElementById("otr-add").hidden; }), add);
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
if (fails.length) { console.log("\n" + fails.length + " FAILED"); process.exit(1); }
|
|
console.log("\nALL PASS");
|
|
})().catch(function (e) { console.error(e); process.exit(1); });
|