plugins/plugins/weixin_redpack/internal/weixin_redpack_test.go

89 lines
2.3 KiB
Go

package internal
import (
"context"
"encoding/json"
"fmt"
"gitea.cdlsxd.cn/sdk/plugin/proto"
"github.com/stretchr/testify/assert"
"plugins/utils/weixin"
"testing"
)
var server = &WeiXinRedPackService{}
func config() []byte {
c := &weixin.Server{
MchID: "1629276485",
MchCertificateSerialNumber: "3C7E21B74C04BE6227A690EB44184F219D763F92",
MchAPIv3Key: "ChengDuBale0123456789qwertyuiopa",
// 商户API私钥
PrivateKeyPath: "/Users/lsxd/code/php/yxxt/market/config/wechatcash/apiclient_key.pem",
}
marshal, _ := json.Marshal(c)
return marshal
}
func TestOrder(t *testing.T) {
request := &proto.OrderRequest{
Config: config(),
Order: &proto.OrderRequest_Order{
OrderNo: "240403164049635931",
Account: "oO3vO5AxRWgTjmMD38FTvnB5Rq6o",
Extra: []byte(`{"app_id":"13100720242", "out_detail_no":"stock_creator_mchid"}`),
},
Product: &proto.OrderRequest_Product{
ProductNo: "",
Extra: []byte(`{"batch_name":"13100720242", "batch_remark":"stock_creator_mchid"}`),
},
}
t.Run("TestOrder", func(t *testing.T) {
got, err := server.Order(context.Background(), request)
if err != nil {
t.Errorf("Order() error = %v", err)
return
}
fmt.Printf("%+v", got)
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
})
}
func TestQuery(t *testing.T) {
request := &proto.QueryRequest{
Config: config(),
Order: &proto.QueryRequest_Order{
OrderNo: "",
TradeNo: "202408211517304392270563",
Account: "",
Extra: []byte(`{"out_detail_no":"20240821151730439227056399842027"}`),
},
}
t.Run("TestQuery", func(t *testing.T) {
got, err := server.Query(context.Background(), request)
if err != nil {
t.Errorf("Query() error = %v", err)
return
}
fmt.Printf("%+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: []byte(``),
Headers: []byte(``),
Body: []byte(``),
}
t.Run("TestNotify", func(t *testing.T) {
got, err := server.Notify(context.Background(), in)
if err != nil {
t.Errorf("Notify() error = %v", err)
return
}
fmt.Printf("TestNotify : %+v \n", got)
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
})
}