修复拉卡拉支付时间偏差

This commit is contained in:
yml2213
2026-06-07 20:42:57 +08:00
parent 44747e7bae
commit 954c3d6be3
10 changed files with 169 additions and 5 deletions
@@ -2,8 +2,12 @@ package payment
import (
"testing"
"time"
"hfb_sys/backend/internal/model"
"hfb_sys/backend/internal/timeutil"
"gorm.io/datatypes"
)
func TestCanReuseOrderPaymentRejectsTerminalAndOldChannel(t *testing.T) {
@@ -85,3 +89,42 @@ func TestNewOrderPaymentUsesPaymentNoAsThirdOrderID(t *testing.T) {
t.Fatalf("payment order fields mismatch: %+v", payment)
}
}
func TestCanReuseOrderPaymentRejectsExpiredCashier(t *testing.T) {
runtimeConfig := runtimePaymentConfig{
Provider: "lakala",
MerchantID: "M2",
}
expiredPayment := model.PaymentOrder{
Status: "paying",
Provider: "lakala",
MerchantID: "M2",
RawRequest: datatypes.JSON([]byte(`{"order_efficient_time":"20000101000000"}`)),
}
if canReuseOrderPayment(expiredPayment, runtimeConfig) {
t.Fatal("canReuseOrderPayment() = true, want false for expired cashier")
}
activePayment := expiredPayment
activePayment.RawRequest = datatypes.JSON([]byte(`{"order_efficient_time":"20990101000000"}`))
if !canReuseOrderPayment(activePayment, runtimeConfig) {
t.Fatal("canReuseOrderPayment() = false, want true for active cashier")
}
}
func TestParseChannelTimeUsesShanghaiWhenLocalIsUTC(t *testing.T) {
oldLocal := time.Local
time.Local = time.UTC
defer func() {
time.Local = oldLocal
}()
parsed := parseChannelTime("20260607202700")
if parsed == nil {
t.Fatal("parseChannelTime() = nil")
}
got := parsed.In(timeutil.ShanghaiLocation()).Format("20060102150405")
if got != "20260607202700" {
t.Fatalf("parseChannelTime() = %s, want 20260607202700 in Asia/Shanghai", got)
}
}