补上43101保留原始错误信息的区分性断言,修复wx测试的恢复时机
- reminder.test.js:43101用例新增对 remind_logs.error 的断言,区分 「真发送失败」(应为微信原始错误信息)与「因halted被跳过」(应为 quota_exhausted兜底文案),此前该区别完全没有测试覆盖 - wx.test.js:把恢复 axios.get/post 的语句移入 try/finally,避免断言 先抛错时污染同进程内后续用例 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+21
-18
@@ -13,23 +13,26 @@ test('微信返回非 0 errcode 时,抛出的 Error 对象应带上原始 errc
|
||||
const restoreGet = axios.get
|
||||
const restorePost = axios.post
|
||||
|
||||
// getAccessToken 走 axios.get,sendSubscribeMessage 走 axios.post,两个都要 mock
|
||||
axios.get = async () => ({ data: { access_token: 'fake_token', expires_in: 7200 } })
|
||||
axios.post = async () => ({ data: { errcode: 43101, errmsg: 'user refuse to accept the msg' } })
|
||||
try {
|
||||
// getAccessToken 走 axios.get,sendSubscribeMessage 走 axios.post,两个都要 mock
|
||||
axios.get = async () => ({ data: { access_token: 'fake_token', expires_in: 7200 } })
|
||||
axios.post = async () => ({ data: { errcode: 43101, errmsg: 'user refuse to accept the msg' } })
|
||||
|
||||
await assert.rejects(
|
||||
() => wx.sendSubscribeMessage({
|
||||
touser: 'oTest',
|
||||
page: 'pages/index/index',
|
||||
templateId: 'tplTest',
|
||||
data: {}
|
||||
}),
|
||||
(err) => {
|
||||
assert.strictEqual(err.errcode, 43101, 'Error 对象应带上微信返回的原始 errcode,而不是靠字符串匹配')
|
||||
return true
|
||||
}
|
||||
)
|
||||
|
||||
axios.get = restoreGet
|
||||
axios.post = restorePost
|
||||
await assert.rejects(
|
||||
() => wx.sendSubscribeMessage({
|
||||
touser: 'oTest',
|
||||
page: 'pages/index/index',
|
||||
templateId: 'tplTest',
|
||||
data: {}
|
||||
}),
|
||||
(err) => {
|
||||
assert.strictEqual(err.errcode, 43101, 'Error 对象应带上微信返回的原始 errcode,而不是靠字符串匹配')
|
||||
return true
|
||||
}
|
||||
)
|
||||
} finally {
|
||||
// 断言先抛错也要恢复,避免污染同进程内后续用例
|
||||
axios.get = restoreGet
|
||||
axios.post = restorePost
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user