57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
package integration
|
|
|
|
import (
|
|
bizpayment "kra/internal/biz/payment"
|
|
"testing"
|
|
)
|
|
|
|
func TestPaymentSelectLabelsKeepProtocolValues(t *testing.T) {
|
|
for _, test := range []struct {
|
|
provider, key, value, label string
|
|
}{
|
|
{bizpayment.PaymentWechatV3, "trade_type", "native", "扫码支付 (native)"},
|
|
{bizpayment.PaymentWechatV2, "trade_type", "MICROPAY", "付款码支付 (MICROPAY)"},
|
|
{bizpayment.PaymentAlipay, "method", "alipay.trade.wap.pay", "手机网站支付 (alipay.trade.wap.pay)"},
|
|
} {
|
|
definition, ok := IntegrationDefinition(IntegrationKindPayment, test.provider)
|
|
if !ok {
|
|
t.Fatalf("missing definition %s", test.provider)
|
|
}
|
|
found := false
|
|
for _, field := range definition.Fields {
|
|
if field.Key != test.key {
|
|
continue
|
|
}
|
|
for _, option := range field.Options {
|
|
if option.Value == test.value {
|
|
found = true
|
|
if option.Label != test.label {
|
|
t.Errorf("%s/%s label = %q, want %q", test.provider, test.value, option.Label, test.label)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("missing option %s/%s", test.provider, test.value)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestWechatV3PlatformCertificateIsOptional(t *testing.T) {
|
|
definition, _ := IntegrationDefinition(IntegrationKindPayment, bizpayment.PaymentWechatV3)
|
|
for _, field := range definition.Fields {
|
|
if field.Key == "platform_cert" && field.Required {
|
|
t.Fatal("platform certificate is marked required")
|
|
}
|
|
}
|
|
values := DefaultIntegrationConfig(IntegrationKindPayment, bizpayment.PaymentWechatV3)
|
|
values["app_id"] = "wx-app"
|
|
values["merchant_id"] = "merchant"
|
|
values["serial_no"] = "merchant-serial"
|
|
values["private_key"] = "merchant-private-key"
|
|
values["api_v3_key"] = "01234567890123456789012345678901"
|
|
if err := ValidateIntegrationConfig(IntegrationKindPayment, bizpayment.PaymentWechatV3, values); err != nil {
|
|
t.Fatalf("valid merchant credentials rejected without platform certificate: %v", err)
|
|
}
|
|
}
|