商品相关接口
This commit is contained in:
112
weipinshang/goods_api_test.go
Normal file
112
weipinshang/goods_api_test.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package wps_test
|
||||
|
||||
import (
|
||||
wps "git.ssgfgtfy.com/public/ssgf_utils/weipinshang"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func setupMockServer(path string, method string, response string, t *testing.T) *httptest.Server {
|
||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "/"+path, r.URL.Path)
|
||||
assert.Equal(t, method, r.Method)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(response))
|
||||
}))
|
||||
}
|
||||
|
||||
func newClientWithServer(ts *httptest.Server) *wps.WeiPinShangClient {
|
||||
return wps.NewWeiPinShangClient(wps.Config{
|
||||
BaseURL: wps.DevHost,
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetGoodBrand(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodBrandURL, http.MethodPost, `{"code":200,"data":{"brands":[]}}`, t)
|
||||
defer ts.Close()
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodBrand(wps.GoodBrandReq{
|
||||
PageNo: "2",
|
||||
PageSize: "2",
|
||||
CBrandName: "测试",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsClassify(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsClassifyURL, http.MethodPost, `{"code":200,"data":{"classify":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsClassify(wps.GetGoodsClassifyReq{
|
||||
CLevel: "2",
|
||||
CParentCode: "13315",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsList(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsListURL, http.MethodPost, `{"code":200,"data":{"goods":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsList(wps.GetGoodsListReq{
|
||||
PageNo: "1",
|
||||
PageSize: "10",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsdept(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsdeptURL, http.MethodPost, `{"code":200,"data":{"list":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsdept(wps.GetGoodsdeptReq{})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetDetailsGoods(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetDetailsGoodsUrl, http.MethodPost, `{"code":200,"data":{"details":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetDetailsGoods(wps.GetDetailsGoodsReq{
|
||||
FatherId: "WPS9_282520,WPS9_282450",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsDetails(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsDetailsURL, http.MethodPost, `{"code":200,"data":{"goodsInfo":{}}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsDetails(wps.GetGoodsDetailsReq{
|
||||
FatherId: "WPS9_282520",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsStock(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsStockURL, http.MethodPost, `{"code":200,"data":{"stocks":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsStock(wps.GetGoodsStockReq{
|
||||
FatherId: "WPS9_282520",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
Reference in New Issue
Block a user