2025-05-15 17:59:51 +08:00
|
|
|
|
package zhetaoke
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// api-单元测试
|
|
|
|
|
|
type apiClientSuite struct {
|
|
|
|
|
|
suite.Suite
|
|
|
|
|
|
api ZheTaoKeApi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestApiClient(t *testing.T) {
|
|
|
|
|
|
suite.Run(t, new(apiClientSuite))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *apiClientSuite) SetupSuite() {
|
|
|
|
|
|
log := logx.WithContext(context.Background())
|
|
|
|
|
|
apiClient := NewApiClient(log, AuthConfig{
|
2025-05-16 18:02:51 +08:00
|
|
|
|
AppKey: "de6307e7af054f69bd2506696d96e47d",
|
|
|
|
|
|
UnionId: "2036695914",
|
2025-05-15 17:59:51 +08:00
|
|
|
|
})
|
|
|
|
|
|
a.api = apiClient
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *apiClientSuite) Test_PromotionLink() {
|
|
|
|
|
|
data := PromotionLinkRequest{
|
2025-05-16 18:02:51 +08:00
|
|
|
|
MaterialId: "https://u.jd.com/r6NhFBF", //推广物料url,例如活动链接、商品链接等;支持仅传入skuid
|
|
|
|
|
|
PositionId: 131, //自定义推广位id,自定义的数字,自己在本地跟用户做好关联,订单中会透出自定义的数字
|
2025-05-15 17:59:51 +08:00
|
|
|
|
ChainType: 3, // 转链类型,1:长链, 2 :短链 ,3: 长链+短链,默认短链,短链有效期60天
|
|
|
|
|
|
}
|
|
|
|
|
|
resp, err := a.api.PromotionLink(data)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
a.T().Errorf("=====[Test_PromotionLink] err: %v", err)
|
|
|
|
|
|
}
|
|
|
|
|
|
a.T().Logf("=====[Test_PromotionLink] resp: %+v, err: %v", resp, err)
|
|
|
|
|
|
if resp != nil {
|
|
|
|
|
|
va, _ := json.Marshal(resp.Data)
|
|
|
|
|
|
fmt.Println(string(va))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|