b1f8fbb6e4
Anchor queries boost retrieval for diplomacy, finance, and AI headlines; inline conversion now reads news002 wc/we/wt weather cards so drafts show city forecasts again. Co-authored-by: Cursor <cursoragent@cursor.com>
72 lines
2.7 KiB
JavaScript
72 lines
2.7 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('buildWeatherPushTextFromHtml supports news002 wc/we/wt cards', () => {
|
|
const html = `<div class="weather-grid">
|
|
<div class="weather-card"><div class="wc">北京</div><div class="we">🌤</div><div class="wt">14/26℃</div></div>
|
|
</div>`;
|
|
const text = buildWeatherPushTextFromHtml(html, { city: '北京' });
|
|
assert.match(text, /14\/26℃/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);
|
|
});
|