Files
memind/wechat/push-content/weather-delivery.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

64 lines
2.3 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 {
buildWeatherPushTextFromHtml,
formatWeatherPushDelivery,
normalizePushWeatherCity,
} from './weather-delivery.mjs';
const WEATHER_HTML = `<!DOCTYPE html><html><body>
<div class="date-badge">2026年9月20日</div>
<div class="weather-today"><p>全国大部晴到多云</p></div>
<div class="weather-grid">
<div class="weather-card"><div class="w-left"><span class="w-city">北京</span><span class="w-cond">☀️ 晴</span></div><div class="w-right"><span class="w-temp">28°</span></div></div>
<div class="weather-card"><div class="w-left"><span class="w-city">上海</span><span class="w-cond">🌧️ 小雨</span></div><div class="w-right"><span class="w-temp">24°</span></div></div>
</div>
</body></html>`;
test('buildWeatherPushTextFromHtml renders city card and dressing advice', () => {
const text = buildWeatherPushTextFromHtml(WEATHER_HTML, { city: '北京' });
assert.match(text, /🌤 每日天气 · 北京/u);
assert.match(text, /☀️ 晴/u);
assert.match(text, /穿衣建议/u);
assert.match(text, /上海/u);
});
test('normalizePushWeatherCity strips suffix 市', () => {
assert.equal(normalizePushWeatherCity('北京市'), '北京');
});
test('formatWeatherPushDelivery reads weather section from today news page', async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'weather-push-'));
const userId = 'weather-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'), WEATHER_HTML);
const delivery = await formatWeatherPushDelivery({
city: '上海',
now: Date.parse('2026-09-20T07:00: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.match(delivery.text, /上海/u);
assert.match(delivery.text, /小雨/u);
});