plugins/plugins/qixing_wechat_redpack/internal/qixing_wechat_redpack_test.go

132 lines
3.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package internal
import (
"context"
"encoding/json"
"fmt"
"gitea.cdlsxd.cn/sdk/plugin/proto"
"github.com/stretchr/testify/assert"
"testing"
)
var server = &QiXingWechatRedPackService{}
// config
// https://ceshi.myviding.com/cdc-api/api/external/red-packet 测试
// https://cdc.myviding.com/cdc-api/api/external/red-packet 生产
func config() []byte {
c := &Config{
Mode: "wechat_redpack_mode",
NchName: "启星微信红包",
AppKey: "ZU2Y2HHQK00N5TP4",
BatchId: "20062389",
BasUrl: "https://cdc.myviding.com/cdc-api/api/external/red-packet",
NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/supplier/notify/51",
Official: Official{
Name: "福建兴旺网络科技有限公司",
AppId: "wxe3bd59243545fa8a",
AppSecret: "4c9649cb998f71038e187b4c58f5fda0",
OauthKey: "bcee0c6753b2a31c792a91fe9f9f1666",
OauthUrl: "https://utils.85938.cn/utils/v1/wechat/oauth/fjxw",
},
}
marshal, _ := json.Marshal(c)
return marshal
}
func Test_Config(t *testing.T) {
t.Run("TestConfig", func(t *testing.T) {
c := config()
fmt.Printf("%s\n", string(c))
assert.NotEmpty(t, c)
})
}
func Test_Order(t *testing.T) {
request := &proto.OrderRequest{
Config: config(),
Order: &proto.OrderRequest_Order{
OrderNo: "lsxd20250929004",
Account: "ojbqr6HpeWKFy9Sgdx8yCmmeVJiw",
Quantity: 1,
Amount: 0.3,
Extra: []byte(``),
},
Product: &proto.OrderRequest_Product{
ProductNo: "",
Price: 0.3,
Type: 0,
Extra: []byte(`{"batch_name":"batch name恭喜发财红包拿来红包祝福语", "batch_remark":"batch remark 恭喜发财,红包拿来,红包备注", "goods_name":"红包名称xx红包"}`),
},
}
t.Run("Test_Order", func(t *testing.T) {
got, err := server.Order(context.Background(), request)
if err != nil {
t.Errorf("Order() error = %v", err)
return
}
fmt.Printf("响应报文=%s\n", got.Result.Data)
fmt.Printf("%s", got.String())
assert.Equal(t, int(proto.Status_ING), int(got.Result.Status))
})
}
func Test_Query(t *testing.T) {
request := &proto.QueryRequest{
Config: config(),
Order: &proto.QueryRequest_Order{
OrderNo: "lsxd20250929003",
TradeNo: "",
Account: "",
Extra: []byte(``),
},
}
t.Run("Test_Query", 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 Test_Balance(t *testing.T) {
request := &proto.QueryRequest{
Config: config(),
Order: &proto.QueryRequest_Order{
OrderNo: "lsxd202306071545141532",
TradeNo: "",
Account: "",
Extra: []byte(``),
},
}
t.Run("Test_Balance", func(t *testing.T) {
got, err := server.Balance(context.Background(), request)
if err != nil {
t.Errorf("Query() error = %v", err)
return
}
fmt.Printf("%s \n", string(got))
})
}
func TestNotify(t *testing.T) {
in := &proto.NotifyRequest{
Config: config(),
Queries: []byte(``),
Headers: []byte(``),
Body: []byte(`{"bizNo":"lsxd20250929003","sign":"e71e685d8d9544aad0f32e699fd98e06","batchId":"20062389","type":"SENT"}`),
}
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))
})
}