// 已读取AGENTS.md import * as fs from 'fs'; import * as path from 'path'; /** * 第五十七批回归闸门:微信订阅消息(服务通知)真实下发闭环 */ describe('第五十七批微信订阅消息闸门', () => { const rootDir = path.resolve(__dirname, '../../'); const svc = fs.readFileSync(path.join(rootDir, 'server/src/core/notify/wechat-subscribe.service.ts'), 'utf-8'); const indexCode = fs.readFileSync(path.join(rootDir, 'server/src/index.ts'), 'utf-8'); const apiCode = fs.readFileSync(path.join(rootDir, 'pwuniapp/common/api.js'), 'utf-8'); const settings = fs.readFileSync(path.join(rootDir, 'pwuniapp/pages/user/settings.vue'), 'utf-8'); it('提供微信订阅消息下发客户端', () => { expect(svc).toContain('export function sendSubscribeMessageHttp('); expect(svc).toContain("cgi-bin/message/subscribe/send"); expect(svc).toContain('export function buildTemplateData('); }); it('服务端按配置真实下发并接入触发点(字段与所选公共模板对齐)', () => { expect(indexCode).toContain('async function notifyBySubscribe('); expect(indexCode).toContain("app.get('/api/message/subscribe-templates'"); expect(indexCode).toContain('sendSubscribeMessageHttp(accessToken'); for (const key of ['orderStatus', 'activityJoin', 'withdrawSuccess']) { expect(indexCode).toContain(`notifyBySubscribe('${key}'`); } // 订单状态提醒模板字段 expect(indexCode).toContain('character_string1:'); expect(indexCode).toContain('phrase2:'); expect(indexCode).toContain('thing3:'); expect(indexCode).toContain('thing4:'); // 提现审核通知模板字段 expect(indexCode).toContain('amount2:'); expect(indexCode).toContain('phrase5:'); expect(indexCode).toContain('time7:'); expect(indexCode).toContain('amount8:'); // 活动报名成功通知模板字段 expect(indexCode).toContain('thing1:'); expect(indexCode).toContain('time2:'); expect(indexCode).toContain('time3:'); // 开始时间兜底:非标准日期回退当前时间,避免 time 字段 47003 expect(indexCode).toContain('function toCnTimeOrNow('); expect(indexCode).toContain('time3: toCnTimeOrNow(act?.startTime)'); }); it('管理端测试推送在就绪时真实下发,未就绪时明确标注模拟原因', () => { const start = indexCode.indexOf("app.post('/api/admin/message/test-send'"); const nextApp = indexCode.indexOf('\napp.', start + 10); const block = indexCode.slice(start, nextApp > 0 ? nextApp : start + 8000); expect(block).toContain("mode: ok ? 'REAL' : 'REAL_FAILED'"); expect(block).toContain("mode: 'SIMULATED'"); // 未下发时必须返回明确原因与配置自检,避免被误解为"已发送成功" expect(block).toContain('diagnostics'); expect(block).toContain('reason'); }); it('小程序用真实模板ID 请求订阅授权', () => { expect(apiCode).toContain('export async function getSubscribeTemplates('); expect(apiCode).toContain('/message/subscribe-templates'); expect(settings).toContain('requestNoticeSubscribe'); expect(settings).not.toContain("'ORDER_STATUS_NOTICE_TMPL'"); }); });