third-platform-sdk/platform/meituan/api_test.go

96 lines
2.2 KiB
Go
Raw Permalink Normal View History

2024-11-26 15:40:56 +08:00
package meituan
import (
"context"
"encoding/json"
"testing"
"github.com/stretchr/testify/suite"
"github.com/zeromicro/go-zero/core/logx"
)
// api-单元测试
type apiClientSuite struct {
suite.Suite
api MeituanApi
}
func TestApiClient(t *testing.T) {
suite.Run(t, new(apiClientSuite))
}
func (a *apiClientSuite) SetupSuite() {
log := logx.WithContext(context.Background())
apiClient := NewApiClient(log, AuthConfig{
AppKey: "",
AppSecret: "",
})
a.api = apiClient
}
func (a *apiClientSuite) Test_Sign() {
data := map[string]interface{}{
"name": "zhangsan",
"phone": "13800000001",
}
sign := a.api.Sign("POST", "/t3/union/test", data)
a.T().Logf("=====[TestSign] sign: %s", sign)
}
func (a *apiClientSuite) Test_GenerateLink() {
req := GenerateLinkRequest{
LinkType: 1,
ActId: "7",
Sid: "f3a8c1",
}
result, err := a.api.GenerateLink(context.Background(), req)
if !a.NoError(err) {
a.T().Errorf("========[Test_GenerateLink] response error:%s", err)
return
}
resultByte, err := json.Marshal(result)
if err != nil {
a.T().Errorf("========[Test_GenerateLink] json_marshal error:%s", err)
return
}
a.T().Logf("=====[Test_GenerateLink] result: %s", string(resultByte))
}
func (a *apiClientSuite) Test_QueryOrderList() {
req := QueryOrderListRequest{
Page: 1,
Limit: 2,
}
result, err := a.api.QueryOrderList(context.Background(), req)
if !a.NoError(err) {
a.T().Errorf("========[Test_QueryOrderList] response error:%s", err)
return
}
resultByte, err := json.Marshal(result)
if err != nil {
a.T().Errorf("========[Test_QueryOrderList] json_marshal error:%s", err)
return
}
a.T().Logf("=====[Test_QueryOrderList] result: %s", string(resultByte))
}
func (a *apiClientSuite) Test_QueryCouponList() {
req := QueryCouponListRequest{
PageNo: 1,
PageSize: 2,
Platform: 1,
SearchText: "券",
}
result, err := a.api.QueryCouponList(context.Background(), req)
if !a.NoError(err) {
a.T().Errorf("========[Test_QueryCouponList] response error:%s", err)
return
}
resultByte, err := json.Marshal(result)
if err != nil {
a.T().Errorf("========[Test_QueryCouponList] json_marshal error:%s", err)
return
}
a.T().Logf("=====[Test_QueryCouponList] result: %s", string(resultByte))
}