package internal import ( "context" "encoding/json" "fmt" "gitea.cdlsxd.cn/sdk/plugin/proto" "github.com/stretchr/testify/assert" "testing" ) var zltx = &ZLTXCardService{} func config() []byte { c := &Config{ AppId: "23329", AppKey: "8db16e8cc8363ed4eb4c14f9520bcc32", BaseUri: "http://test.openapi.1688sup.cn", NotifyUrl: "http://test.openapi.1688sup.cn", } 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_card_zltx_4", Account: "18666666666", Quantity: 1, Amount: 0, Extra: nil, }, Product: &proto.OrderRequest_Product{ ProductNo: "222", Extra: []byte(`{}`), }, } t.Run("TestOrder", func(t *testing.T) { got, err := zltx.Order(context.Background(), request) if err != nil { t.Errorf("Order() error = %v", err) return } fmt.Printf("%+v", 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_card_zltx_4", TradeNo: "", Account: "", Extra: nil, }, } t.Run("TestQuery", func(t *testing.T) { got, err := zltx.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: nil, Headers: nil, Body: []byte(`{"merchantId":10, "outTradeNo":"123", "rechargeAccount":"1866666666", "status":"01", "sign":"sign"}`), } t.Run("TestNotify", func(t *testing.T) { got, err := zltx.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)) }) }