补充发送侧分组与错误分支的测试覆盖,保留43101原始错误信息的修复

- reminder.js:43101 跳过日志改为记录微信原始错误信息,便于和「额度耗尽」的
  兜底文案区分排查(前一实施者已验证,此次原样带入提交)
- reminder.test.js:新增 runOnce 按 openid 分组结算用例,验证多用户额度互不
  串号;将「非额度类错误」用例扩到 2 条数据,证明该分支不会误中止后续发送
- 新建 wx.test.js:验证 sendSubscribeMessage 在微信返回非 0 errcode 时,
  抛出的 Error 对象确实带有正确的 errcode 属性

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
yuming
2026-08-16 09:07:46 +08:00
parent 6548577a98
commit 57470ade4f
3 changed files with 91 additions and 7 deletions
+6 -4
View File
@@ -84,14 +84,16 @@ async function runForUser(openid, items, today = new Date()) {
let halted = false
let ok = 0, fail = 0, skipped = 0
const logSkip = (item) => insertLog.run({
// errorMsg 默认是「根本没发请求」的兜底文案;真正打了请求并被 43101 拒绝的那一条
// 会传入微信返回的原始错误信息,两者都记为 skipped,但 error 字段要能区分开
const logSkip = (item, errorMsg = 'quota_exhausted') => insertLog.run({
anniversaryId: item.anniv.id,
personName: item.anniv.personName,
typeName: getTypeName(item.anniv.type, item.anniv.customTypeName),
daysUntil: item.daysUntil,
sendDate: Date.now(),
status: 'skipped',
error: 'quota_exhausted'
error: errorMsg
})
for (const item of due) {
@@ -129,8 +131,8 @@ async function runForUser(openid, items, today = new Date()) {
quota.reset(openid)
balance = 0
halted = true
logSkip(item); skipped++
console.warn(`[reminder] ${openid} 额度已耗尽,本轮剩余全部跳过`)
logSkip(item, err.message); skipped++
console.warn(`[reminder] ${openid} 额度已耗尽,本轮剩余全部跳过: ${err.message}`)
} else {
insertLog.run({
anniversaryId: anniv.id, personName: anniv.personName, typeName: null,