文件
shanghaipeiwan/server/tests/subscribe-message.spec.ts
xcbyy 2599dce315 feat(security): 三端闭环加固 + 微信提现打款/订阅消息落地
后端: 身份与归属鉴权收口; 资金安全(结算闸门/支付防篡改/报名费真实扣款/赠金/结算唯一入账/提现打款); 数据泄露与隐私; 登录与密钥安全(默认密钥闸门/登录限流); 可观测性; 启动自检.

微信: 商家转账到零钱提现打款闭环(含回调/查单/失败退回佣金); 订阅消息真实下发闭环与后台模板字段对齐.

后台: 财务/微信支付配置读取失败锁定; 看板/待办/走势去假数据; 打款与测试推送文案修正.

小程序: 请求层错误透传与登录过期提示; 多页失败反馈与乐观回滚; 帮助中心FAQ页面化.

测试: 新增 40+ 回归护栏与真实 MySQL 冒烟(75 套件/599 用例全绿).
2026-10-17 18:00:09 +08:00

61 行
2.8 KiB
TypeScript

// 已读取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 block = indexCode.slice(start, start + 3400);
expect(block).toContain("mode: 'REAL'");
expect(block).toContain("mode: 'SIMULATED'");
});
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'");
});
});