263 lines
5.7 KiB
Go
263 lines
5.7 KiB
Go
package jdapi
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.rosy.net.cn/baseapi"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
)
|
|
|
|
func TestQueryPageBrandInfo(t *testing.T) {
|
|
result, _, err := api.QueryPageBrandInfo(0, 0, 0, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(result) == 0 {
|
|
t.Fatal("QueryPageBrandInfo brand list is empty!")
|
|
}
|
|
// baseapi.SugarLogger.Debug(result[0])
|
|
}
|
|
|
|
func TestQueryCategoriesByOrgCode(t *testing.T) {
|
|
result, err := api.QueryCategoriesByOrgCode()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(result) == 0 {
|
|
t.Fatal("QueryCategoriesByOrgCode category list is empty!")
|
|
}
|
|
}
|
|
|
|
func TestQueryChildCategoriesForOP(t *testing.T) {
|
|
result, err := api.QueryChildCategoriesForOP(0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(result) == 0 {
|
|
t.Fatal("QueryChildCategoriesForOP jd category list is empty!")
|
|
}
|
|
}
|
|
|
|
func TestBatchUpdateOutSkuId(t *testing.T) {
|
|
result, err := api.BatchUpdateOutSkuId([]*SkuIDPair{
|
|
&SkuIDPair{
|
|
SkuId: 2012286956,
|
|
OutSkuId: "2",
|
|
},
|
|
&SkuIDPair{
|
|
SkuId: 2029317908,
|
|
OutSkuId: "34523",
|
|
},
|
|
&SkuIDPair{
|
|
SkuId: 2012286957,
|
|
OutSkuId: "3",
|
|
},
|
|
})
|
|
baseapi.SugarLogger.Debug(utils.Format4Output(result, false), err)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestQuerySkuInfos(t *testing.T) {
|
|
pageSize := MaxSkuIDsCount4QueryListBySkuIds
|
|
pageNo := 1
|
|
var skuList []*SkuMain
|
|
for {
|
|
result, totalCount, err := api.QuerySkuInfos(&QuerySkuParam{
|
|
PageSize: pageSize,
|
|
PageNo: pageNo,
|
|
IsFilterDel: IsFilterDelTrue,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
skuList = append(skuList, result...)
|
|
if len(skuList) >= totalCount {
|
|
break
|
|
}
|
|
pageNo++
|
|
}
|
|
var abnormalSkuList []*SkuMain
|
|
for _, v := range skuList {
|
|
if len(v.ShopCategories) == 0 {
|
|
abnormalSkuList = append(abnormalSkuList, v)
|
|
}
|
|
}
|
|
t.Log(utils.Format4Output(abnormalSkuList, false))
|
|
t.Log(len(abnormalSkuList))
|
|
}
|
|
|
|
func TestQueryListBySkuIds(t *testing.T) {
|
|
ids := []int64{
|
|
2018806493,
|
|
2018805873,
|
|
}
|
|
result, err := api.QueryListBySkuIds(&QueryListBySkuIdsParam{
|
|
SkuIDs: ids,
|
|
})
|
|
t.Log(utils.Format4Output(result, false))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(result) != len(ids) {
|
|
baseapi.SugarLogger.Debug(result)
|
|
t.Fatalf("QueryListBySkuIds result size is not same as requested:%d", len(ids))
|
|
}
|
|
}
|
|
|
|
func TestQueryKeyWordDicInfo(t *testing.T) {
|
|
result, totalCount, err := api.QueryKeyWordDicInfo(0, 0, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(result) == 0 || totalCount == 0 {
|
|
t.Fatalf("QueryKeyWordDicInfo size is wrong")
|
|
}
|
|
// baseapi.SugarLogger.Debug(result[0], totalCount)
|
|
}
|
|
|
|
func TestSyncProduct(t *testing.T) {
|
|
result, err := api.SyncProduct(mustExistStoreID, "2022250244")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
baseapi.SugarLogger.Debug(result)
|
|
result, err = api.SyncProduct("wrongstoreid", "2022250244")
|
|
if err == nil {
|
|
t.Fatal("SyncProduct should return error")
|
|
}
|
|
result, err = api.SyncProduct(mustExistStoreID, "wrongskuid")
|
|
if err == nil {
|
|
t.Fatal("SyncProduct should return error")
|
|
}
|
|
}
|
|
|
|
func TestGetProductStatust(t *testing.T) {
|
|
result, err := api.GetProductStatus(mustExistStoreID, "2022250244")
|
|
if err != nil || result == nil {
|
|
t.Fatal(err)
|
|
}
|
|
// baseapi.SugarLogger.Debug(result)
|
|
result, err = api.GetProductStatus("wrongstoreid", "2022250244")
|
|
if err == nil {
|
|
t.Fatal("GetProductStatus should return error")
|
|
}
|
|
result, err = api.GetProductStatus(mustExistStoreID, "wrongskuid")
|
|
if err == nil {
|
|
t.Fatal("GetProductStatus should return error")
|
|
}
|
|
}
|
|
|
|
func TestAddShopCategory(t *testing.T) {
|
|
result, err := api.AddShopCategory(0, "hello", 1, 0, "test")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(result)
|
|
}
|
|
|
|
func TestDelShopCategory(t *testing.T) {
|
|
err := api.DelShopCategory(5259045)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestGetSkuSaleAttrName(t *testing.T) {
|
|
result, err := api.GetSkuSaleAttrName()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestGetSpuSaleAttr(t *testing.T) {
|
|
result, err := api.GetSpuSaleAttr("3628")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestAddSku(t *testing.T) {
|
|
str := `
|
|
{"brandId":35247,
|
|
"categoryId":20847,
|
|
"fixedStatus":1,
|
|
"ifViewDesc":0,
|
|
"images":["http://image.jxc4.com/e42be71501d0fbb841743bfb7a9ebbcf.jpg"],
|
|
"isSale":false,
|
|
"outSkuId":"123",
|
|
"shopCategories":[4247719],
|
|
"skuName":"黑3龙江冰宝珍珠米10kg/袋",
|
|
"skuPrice":7245,"traceId":"4414AEAD1CCA11EAB689525400E86DC0,xujianhua","weight":1}
|
|
`
|
|
var param *OpSkuParam
|
|
err := utils.UnmarshalUseNumber([]byte(str), ¶m)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
param.Upc = "66660003446710"
|
|
result, err := api.AddSku2(param)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestBatchAddSku(t *testing.T) {
|
|
paramList := []*CreateByUpcParam{
|
|
&CreateByUpcParam{
|
|
UniqueUpc: "6948939649102",
|
|
OutSku: "50001",
|
|
JdPrice: "2.13",
|
|
ShopCategoryID: 4247719,
|
|
IsSale: true,
|
|
},
|
|
}
|
|
result, err := api.BatchAddSku(paramList)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestGetSpuStatus(t *testing.T) {
|
|
result, err := api.GetSpuStatus("8515")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestUpdateSpuSaleAttr(t *testing.T) {
|
|
err := api.UpdateSpuSaleAttr("3628", "1001", "", "10", "hello")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestUpdateSpu(t *testing.T) {
|
|
err := api.UpdateSpu("8620", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestUpdateSku(t *testing.T) {
|
|
_, err := api.UpdateSku("27379", map[string]interface{}{
|
|
"upc": "ttld20190712",
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestUpdateShopCategory(t *testing.T) {
|
|
err := api.UpdateShopCategory(4760208, "中秋必抢🍳")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|