98 lines
2.5 KiB
Go
98 lines
2.5 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,
|
|
}
|
|
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(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=1,sign=CA2F9A1C822AC95A2E2BF175F7403A93"],"Connection":["close"],"Content-Length":["145"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`),
|
|
Body: []byte(`{"merchantId":23329,"outTradeNo":"test_plugin_zltx_v1_card_3","tradeNo":"716590229825404929","status":"01","cardCode":"bplpAB7dQzSD9xczvO7WGQ=="}`),
|
|
}
|
|
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))
|
|
})
|
|
}
|