Files
slogan/server/styleagent/service/payment_order_test.go
T
admin a6de9ebd12 Add 'server/' from commit 'e64421295fff83acbb6d6ab3d3b27f3ef8368f00'
git-subtree-dir: server
git-subtree-mainline: c4e617ada7
git-subtree-split: e64421295f
2026-08-04 15:02:35 +08:00

57 lines
1.5 KiB
Go

package service
import "testing"
func TestPaymentSignDeterministic(t *testing.T) {
params := map[string]string{
"appid": "1000", "trade_order_id": "ORDER001", "total_fee": "29.90",
}
s1 := paymentSign(params, "secret123")
s2 := paymentSign(params, "secret123")
if s1 != s2 {
t.Fatalf("相同参数签名应一致: %s != %s", s1, s2)
}
if s1 == "" {
t.Fatal("签名不应为空")
}
}
func TestPaymentSignChangesWithSecret(t *testing.T) {
params := map[string]string{"appid": "1000", "trade_order_id": "ORDER001"}
if paymentSign(params, "a") == paymentSign(params, "b") {
t.Fatal("不同 secret 签名应不同")
}
}
func TestPaymentVerifyNotify(t *testing.T) {
params := map[string]string{
"appid": "1000", "trade_order_id": "ORDER001", "total_fee": "29.90",
"status": "OD", "hash": "",
}
hash := paymentSign(params, "secret123")
if !PaymentOrderService.VerifyNotify(params, hash, "secret123") {
t.Fatal("正确签名应通过验签")
}
params["total_fee"] = "0.01"
if PaymentOrderService.VerifyNotify(params, hash, "secret123") {
t.Fatal("篡改参数后应验签失败")
}
if PaymentOrderService.VerifyNotify(params, hash, "wrong-secret") {
t.Fatal("错误 secret 应验签失败")
}
}
func TestPaymentConfigDisabledWhenEmpty(t *testing.T) {
cfg := PaymentOrderService.getPaymentConfig(t.Context())
if cfg.Enabled {
t.Fatal("默认配置(key 为空)应 disabled")
}
}
func TestNextExpireFormat(t *testing.T) {
exp := NextExpire(nil, 30)
if len(exp) != 19 {
t.Fatalf("过期时间应 YYYY-MM-DD HH:MM:SS 格式: %q", exp)
}
}