Files
memind/wechat/push-content/news-section-extract.test.mjs
T
john 830f8a4011
Memind CI / Test, build, and release guards (push) Successful in 5m36s
feat(wechat): add service-account push subscriptions and news morning cover delivery
Ship the 10-item numeric subscription loop on WeChat MP, wire schedule delivery
for news/weather/quote/health/finance/tech/knowledge/night/surprise pushes, and
extend news morning draft cover generation plus a one-shot draft push script.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-20 16:15:15 +08:00

89 lines
2.9 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
import { PUBLIC_ZONE_DIR, PUBLISH_ROOT_DIR } from '../../user-publish.mjs';
import {
buildSectionCardsPushText,
extractCardsFromSectionIds,
extractKnowledgeItemsFromHtml,
loadTodayNewsMorningHtml,
} from './news-section-extract.mjs';
const SAMPLE_HTML = `<!DOCTYPE html><html><body>
<div class="date-badge">2026年9月20日</div>
<div class="section" id="finance">
<div class="section-title">💰 财经</div>
<div class="card"><span class="tag">A股</span><h3>沪指收涨</h3><p>市场震荡走高。</p></div>
</div>
<div class="section" id="tech">
<div class="card"><span class="tag">AI</span><h3>新模型发布</h3><p>多家厂商更新。</p></div>
</div>
<div class="section" id="knowledge">
<div class="knowledge-item"><div class="k-icon">💡</div><h4>网络效应</h4><p>用户越多价值越大。</p></div>
</div>
<div class="section" id="history">
<div class="card"><h3>1969年</h3><p>人类首次登月。</p></div>
</div>
</body></html>`;
test('extractCardsFromSectionIds reads finance and tech sections', () => {
const finance = extractCardsFromSectionIds(SAMPLE_HTML, ['finance']);
assert.equal(finance.length, 1);
assert.match(finance[0].title, /沪指收涨/u);
const tech = extractCardsFromSectionIds(SAMPLE_HTML, ['tech']);
assert.equal(tech.length, 1);
assert.match(tech[0].title, /新模型发布/u);
});
test('extractKnowledgeItemsFromHtml reads knowledge section', () => {
const items = extractKnowledgeItemsFromHtml(SAMPLE_HTML);
assert.equal(items.length, 1);
assert.match(items[0].title, /网络效应/u);
});
test('buildSectionCardsPushText renders numbered digest', () => {
const cards = extractCardsFromSectionIds(SAMPLE_HTML, ['finance']);
const text = buildSectionCardsPushText({
emoji: '💰',
label: '财经市场',
cards,
includeSummary: true,
cancelId: 4,
});
assert.match(text, /💰 财经市场/u);
assert.match(text, /沪指收涨/u);
});
test('loadTodayNewsMorningHtml loads today page from workspace', async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'section-push-'));
const userId = 'section-source';
const publicDir = path.join(root, PUBLISH_ROOT_DIR, userId, PUBLIC_ZONE_DIR);
fs.mkdirSync(publicDir, { recursive: true });
fs.writeFileSync(path.join(publicDir, 'daily-news-0920.html'), SAMPLE_HTML);
const loaded = await loadTodayNewsMorningHtml({
now: Date.parse('2026-09-20T08:30:00+08:00'),
timezone: 'Asia/Shanghai',
h5Root: root,
pool: {
async query() {
return [[{
config_json: JSON.stringify({
sourceUserId: userId,
pageSlugPattern: 'daily-news-*',
timezone: 'Asia/Shanghai',
}),
}], []];
},
},
env: {},
});
assert.ok(loaded.html);
assert.match(loaded.dateLabel, /2026年9月20日/u);
});