93 lines
3.6 KiB
Go
93 lines
3.6 KiB
Go
package eleme_union
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"testing"
|
||
"time"
|
||
|
||
"github.com/stretchr/testify/suite"
|
||
"github.com/zeromicro/go-zero/core/logx"
|
||
|
||
"repository.lenntc.com/lenntc/third-platform-sdk/sdk/topsdk/defaultability/domain"
|
||
"repository.lenntc.com/lenntc/third-platform-sdk/sdk/topsdk/defaultability/request"
|
||
"repository.lenntc.com/lenntc/third-platform-sdk/util/pointer"
|
||
)
|
||
|
||
// api-单元测试
|
||
type apiClientSuite struct {
|
||
suite.Suite
|
||
api ElemeUnionApi
|
||
}
|
||
|
||
func TestApiClient(t *testing.T) {
|
||
suite.Run(t, new(apiClientSuite))
|
||
}
|
||
|
||
func (a *apiClientSuite) SetupSuite() {
|
||
log := logx.WithContext(context.Background())
|
||
apiClient := NewApiClient(log, AuthConfig{
|
||
AppKey: "34632005",
|
||
AppSecret: "b0e6b6654825e6124f743b2528be95d7",
|
||
})
|
||
a.api = apiClient
|
||
}
|
||
|
||
func (a *apiClientSuite) Test_Sign() {
|
||
data := map[string]interface{}{
|
||
"method": "test",
|
||
}
|
||
publicParam := PublicParam{
|
||
Method: "taobao.item.seller.get", // 必传 API接口名称,具体参见各平台API接口文档,例:taobao.item.seller.get
|
||
AppKey: "34632005", // 必传 TOP分配给应用的AppKey。例:12345678
|
||
Session: "", // 可选 用户授权成功后,平台颁发给应用的授权session,详细介绍请点击这里。当此API文档的标签上注明:“需要授权”,则此参数必传;“不需要授权”,则此参数不需要传。
|
||
Timestamp: time.Now().Format("2006-01-02 15:04:05"), // 必传 时间戳,格式为yyyy-MM-dd HH:mm:ss,时区为GMT+8,例如:2016-01-01 12:00:00。淘宝API服务端允许客户端请求最大时间误差为10分钟。
|
||
V: "2.0", // 必传 API协议版本,可选值:2.0
|
||
SignMethod: "md5", // 必传 签名的摘要算法,可选值为:hmac,md5,hmac-sha256。
|
||
Format: "json", // 否 返回内容响应格式。不传默认为xml格式,可选值:xml,json。
|
||
Simplify: false, // 否 是否采用精简JSON返回格式,仅当format=json时有效,可选值:false,true,不传为false。
|
||
}
|
||
|
||
sign := a.api.Sign(publicParam, data)
|
||
a.T().Logf("=====[TestSign] sign: %s", sign)
|
||
}
|
||
|
||
func (a *apiClientSuite) Test_ElemePromotionOfficialActivityGet() {
|
||
req := &request.AlibabaAlscUnionElemePromotionOfficialactivityGetRequest{
|
||
QueryRequest: &domain.AlibabaAlscUnionElemePromotionOfficialactivityGetActivityRequest{
|
||
Pid: pointer.String("alsc_23378482_4796002_15513017"),
|
||
ActivityId: pointer.String("10690111"),
|
||
},
|
||
}
|
||
resp, err := a.api.ElemePromotionOfficialActivityGet(req)
|
||
if err != nil {
|
||
a.T().Errorf("=====[Test_ElemePromotionOfficialActivityGet] err: %v", err)
|
||
return
|
||
}
|
||
a.T().Logf("=====[Test_ElemePromotionOfficialActivityGet] resp: %+v", resp)
|
||
}
|
||
|
||
func (a *apiClientSuite) Test_KbcpxPositiveOrderGet() {
|
||
req := &request.AlibabaAlscUnionKbcpxPositiveOrderGetRequest{
|
||
DateType: pointer.Int64(1),
|
||
//Pid: pointer.String("alsc_23378482_4796002_15513017"),
|
||
BizUnit: pointer.Int64(2),
|
||
PageSize: pointer.Int64(20),
|
||
PageNumber: pointer.Int64(1),
|
||
StartDate: pointer.String("2024-05-16 00:00:00"),
|
||
EndDate: pointer.String("2024-05-17 00:00:00"),
|
||
//OrderId: pointer.String("8036650073745353114"),
|
||
}
|
||
resp, err := a.api.KbcpxPositiveOrderGet(req)
|
||
if err != nil {
|
||
a.T().Errorf("=====[Test_GetOrders] err: %v", err)
|
||
return
|
||
}
|
||
respStr, err := json.Marshal(resp)
|
||
if err != nil {
|
||
a.T().Errorf("=====[Test_GetOrders] err: %v", err)
|
||
return
|
||
}
|
||
a.T().Logf("=====[Test_GetOrders] resp: %+v", string(respStr))
|
||
}
|