From a281fa2a64b0cd40ccfa8db1c101786db1e8e81c Mon Sep 17 00:00:00 2001 From: lik Date: Sun, 8 Nov 2026 12:05:12 +0800 Subject: [PATCH] =?UTF-8?q?test(payment):=20=E8=A1=A5=E5=85=85=E9=80=80?= =?UTF-8?q?=E6=AC=BE=E8=BF=9F=E5=88=B0=E7=BB=93=E6=9E=9C=E4=B8=8D=E5=9B=9E?= =?UTF-8?q?=E9=80=80=E6=94=AF=E4=BB=98=E4=B8=8E=E8=AE=A2=E5=8D=95=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=9A=84=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/payment.test.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/test/payment.test.js b/test/payment.test.js index ff1db48..544c901 100644 --- a/test/payment.test.js +++ b/test/payment.test.js @@ -11,7 +11,8 @@ import { verifyMessageSignature, decryptAesGcm, } from "../utils/wechatpay.js"; -import { createOrderQueryCache } from "../handler/payment.js"; +import { createOrderQueryCache, HandlerPayment } from "../handler/payment.js"; +import { DBModel } from "../models/index.js"; test("元转分按小数点拆位,不经过浮点", () => { assert.equal(yuanToFen("500.00"), 50000); @@ -178,3 +179,37 @@ test("force 可绕过轮询缓存", async () => { await query("T4", { force: true }); assert.equal(calls, 2); }); + +test("退款成功后的迟到处理中结果不会回退支付与订单状态", async () => { + const previous = { + RefundRecord: DBModel.RefundRecord, + PaymentRecord: DBModel.PaymentRecord, + EscortRecord: DBModel.EscortRecord, + }; + let refundFilter = null; + let downstreamWrites = 0; + DBModel.RefundRecord = { + updateOne: async (filter) => { + refundFilter = filter; + return { matchedCount: 0 }; + }, + }; + DBModel.PaymentRecord = { + updateOne: async () => { downstreamWrites += 1; }, + }; + DBModel.EscortRecord = { + updateOne: async () => { downstreamWrites += 1; }, + }; + + try { + const status = await HandlerPayment.applyRefundResult( + { _id: "r1", paymentId: "p1", recordId: "o1", status: "success" }, + { status: "PROCESSING" } + ); + assert.equal(status, "success"); + assert.deepEqual(refundFilter.status, { $ne: "success" }); + assert.equal(downstreamWrites, 0); + } finally { + Object.assign(DBModel, previous); + } +});