plugins/plugins/zltx_card_v1/internal/zltx_card_v1_test.go

106 lines
2.6 KiB
Go

package internal
import (
"context"
"encoding/json"
"fmt"
"gitea.cdlsxd.cn/sdk/plugin/proto"
"github.com/stretchr/testify/assert"
"testing"
)
var cardService = &ZLTXCardV1Service{}
func config() []byte {
c := &Config{
AppId: "1",
AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
BaseUri: "http://test.openapi.1688sup.cn",
NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
MerchantId: 23329,
}
//c := &Config{
// AppId: "101",
// AppKey: "95E7EC7D4A394FF8D11788E5E436DE99",
// BaseUri: "https://openapi.1688sup.com",
// NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
// MerchantId: 25715,
//}
marshal, _ := json.Marshal(c)
return marshal
}
func TestConfig(t *testing.T) {
t.Run("TestConfig", func(t *testing.T) {
c := config()
fmt.Printf("%s\n", string(c))
assert.NotEmpty(t, c)
})
}
func TestOrder(t *testing.T) {
request := &proto.OrderRequest{
Config: config(),
Order: &proto.OrderRequest_Order{
OrderNo: "test_plugin_zltx_v1_card_3",
Account: "",
Quantity: 1,
Extra: nil,
},
Product: &proto.OrderRequest_Product{
ProductNo: "222",
Extra: []byte(`{}`),
},
}
t.Run("TestOrder", func(t *testing.T) {
got, err := cardService.Order(context.Background(), request)
if err != nil {
t.Errorf("Order() error = %v", err)
return
}
t.Logf("%+v\n", got)
assert.Equal(t, int(proto.Status_ING), int(got.Result.Status))
})
}
func TestQuery(t *testing.T) {
request := &proto.QueryRequest{
Config: config(),
Order: &proto.QueryRequest_Order{
OrderNo: "test_plugin_zltx_v1_card_3",
TradeNo: "",
Account: "",
Extra: nil,
},
}
t.Run("TestQuery", func(t *testing.T) {
got, err := cardService.Query(context.Background(), request)
if err != nil {
t.Errorf("Query() error = %v", err)
return
}
t.Logf("%+v\n", got)
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
})
}
func TestNotify(t *testing.T) {
in := &proto.NotifyRequest{
Config: config(),
Queries: nil,
Headers: []byte(`{"Authorization":["MD5 appid=1,sign=A419BC9E70FA82CC07030A041A4DEEC1"]}`),
Body: []byte(`{"merchantId":23369,"outTradeNo":"202501101143088400010016","tradeNo":"732200443106705409","status":"01","cardCode":"R7UVRxu5Zi8SockCksuZ3w=="}`),
}
t.Run("TestNotify", func(t *testing.T) {
got, err := cardService.Notify(context.Background(), in)
if !assert.Nil(t, err) {
t.Errorf("Notify() error = %v", err)
return
}
fmt.Printf("%s \n", got.String())
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
})
}