package elong_hotel import ( "context" "encoding/json" "testing" "github.com/stretchr/testify/suite" "github.com/zeromicro/go-zero/core/logx" ) // api-单元测试 type apiClientSuite struct { suite.Suite api ElongHotelApi } func TestApiClient(t *testing.T) { suite.Run(t, new(apiClientSuite)) } func (a *apiClientSuite) SetupSuite() { log := logx.WithContext(context.Background()) apiClient := NewApiClient(log, AuthConfig{ Token: "dfae91a85341865b", }) a.api = apiClient } func (a *apiClientSuite) Test_GenerateLink() { req := GetExternalChannelConfigRequest{ Trackid: "elong_hotel", } result, err := a.api.GetExternalChannelConfig(context.Background(), req, "huidu") 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_GenerateUrl() { req := GenerateUrlRequest{ ActivityUrl: "/page/home/webview/webview?src=https%3A%2F%2Fmp.elong.com%2Ftenthousandaura%2F%3Factivitycode%3D5fd89a11-7b58-4f5c-8dc9-c360936d4207%26of%3D99810010", Uid: "11111111111111111", } result, err := a.api.GenerateUrl(context.Background(), req) if !a.NoError(err) { a.T().Errorf("========[Test_GenerateUrl] response error:%s", err) return } a.T().Logf("=====[Test_GenerateUrl] result: %s", string(result)) } func (a *apiClientSuite) Test_QueryOrderList() { req := QueryOrderListRequest{ AppId: "", Trackid: "", BeginDate: "2024-07-01 00:00:00", EndDate: "2024-07-01 23:59:59", Update: 1, PageIndex: 0, PageSize: 1, } result, err := a.api.QueryOrderList(context.Background(), req, "huidu") 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)) }