plugin/dctw/v1/api/card/card_test.go

104 lines
2.3 KiB
Go

package card
import (
"bytes"
"context"
"gitea.cdlsxd.cn/sdk/plugin/dctw/v1/core"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"testing"
)
func TestCard_Order(t *testing.T) {
server, err := core.NewDctWServer(
&core.DctWConfig{
AppId: "1",
AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
BaseUri: "http://test.openapi.1688sup.cn",
},
core.WithDebug(true),
)
if err != nil {
t.Fatal(err)
}
a := &Card{DctWServer: server}
req := &Order{
Number: 1,
MerchantId: "23329",
OutTradeNo: "test_card_zltx_1",
ProductId: "222",
Mobile: "18666666666",
NotifyUrl: "http://test.openapi.1688sup.cn",
Version: "1.0",
}
resp, err := a.Order(context.Background(), req)
if err != nil {
t.Error(err)
return
}
if !resp.GetCode().IsSuccess() {
t.Error(resp.Message)
return
}
t.Log(resp)
}
func TestCard_Query(t *testing.T) {
server, err := core.NewDctWServer(&core.DctWConfig{
AppId: "1",
AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
BaseUri: "http://test.openapi.1688sup.cn",
})
if err != nil {
t.Fatal(err)
}
a := &Card{DctWServer: server}
req := &Query{
MerchantId: "23329",
OutTradeNo: "test_card_zltx_1",
Version: "1.0",
}
resp, err := a.Query(context.Background(), req)
if err != nil {
t.Error(err)
return
}
if !resp.GetCode().IsSuccess() {
t.Error(resp.Message)
return
}
t.Log(resp)
assert.Equal(t, resp.Status.IsSuccess(), true, "充值是否成功")
}
func TestCard_Notify(t *testing.T) {
server, err := core.NewDctWServer(&core.DctWConfig{
AppId: "1",
AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
BaseUri: "http://test.openapi.1688sup.cn",
})
if err != nil {
t.Fatal(err)
}
a := &Card{DctWServer: server}
body := []byte(`{"merchantId":23329,"outTradeNo":"202409111714224026320002","rechargeAccount":"18512869479","sign":"474ACB521DEE99551153B6CE108FD06D","status":"01"}`)
headers := make(http.Header)
headers.Set(core.SignKeyName, "MD5 appid=101,sign=292e21f3683219369cf68dede0d45730")
headers.Set("Content-Type", core.ApplicationJSON)
var httpRequest = &http.Request{
Header: http.Header{},
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
}
resp, err := a.Notify(context.Background(), httpRequest)
if err != nil {
t.Error(err)
return
}
t.Log(resp)
assert.Equal(t, resp.Status.IsSuccess(), true, "充值是否成功")
}