67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package shoutu_show
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"testing"
|
|
)
|
|
|
|
// api-单元测试
|
|
type apiClientSuite struct {
|
|
suite.Suite
|
|
api ShouTuShowApi
|
|
}
|
|
|
|
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_GenerateLink() {
|
|
req := GenerateLinkRequest{
|
|
ActivityUrl: "https://cms.zhongdiantui.com/#/pages/toMiniProgram/toMiniProgram",
|
|
Sid: "f3a8c1",
|
|
LinkCode: "aaakfhkahfkadk",
|
|
ActId: "1111",
|
|
}
|
|
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_GenerateWechatUrl() {
|
|
req := GenerateLinkRequest{
|
|
ActivityUrl: "pages/index/index?distributorId=VCiCWwU2&subChannelId=",
|
|
Sid: "f3a8c1",
|
|
}
|
|
result, err := a.api.GenerateWechatUrl(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))
|
|
}
|