package internal import ( "context" "encoding/json" "fmt" "gitea.cdlsxd.cn/BaseSystem/plugin/proto" "github.com/stretchr/testify/assert" "plugins/utils/weixin" "testing" ) var server = &WeiXinCpnService{} func config() []byte { c := &weixin.Config{ MchID: "1605446142", MchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76", MchAPIv3Key: "ChengDuLanSeXiongDi1234567890123", PrivateKeyPath: "/Users/lsxd/code/go/other/mq/wx/wechat_private_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", "stock_creator_mchid":"stock_creator_mchid"}`), }, Product: &proto.OrderRequest_Product{ ProductNo: "3102024032977191", Extra: []byte(`{}`), }, } 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: "69445765514", Account: "oO3vO5AxRWgTjmMD38FTvnB5Rq6o", Extra: []byte(`{"app_id":"wx9ed74283ad25bca1"}`), }, } 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)) }) }