240 lines
5.3 KiB
Go
240 lines
5.3 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 := jdapi.BatchUpdateOutSkuId([]*SkuIDPair{
|
|
// &SkuIDPair{
|
|
// SkuId: 2012286955,
|
|
// OutSkuId: "1",
|
|
// },
|
|
// &SkuIDPair{
|
|
// SkuId: 2012286956,
|
|
// OutSkuId: "2",
|
|
// },
|
|
// &SkuIDPair{
|
|
// SkuId: 2012286957,
|
|
// OutSkuId: "3",
|
|
// },
|
|
// })
|
|
// baseapi.SugarLogger.Debug(result, err)
|
|
}
|
|
|
|
func TestQuerySkuInfos(t *testing.T) {
|
|
pageSize := 20
|
|
result, totalCount, err := api.QuerySkuInfos(&QuerySkuParam{
|
|
IsFilterDel: IsFilterDelTrue,
|
|
})
|
|
t.Log(utils.Format4Output(result, false))
|
|
t.Log(totalCount)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(result) != pageSize || totalCount == 0 {
|
|
baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
|
|
t.Fatalf("QuerySkuInfos result size is not same as requested:%d", pageSize)
|
|
}
|
|
}
|
|
|
|
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(4784689)
|
|
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":"29935",
|
|
"shopCategories":[4247719],
|
|
"skuName":"黑2龙江冰宝珍珠米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 = "6666000029935"
|
|
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)
|
|
}
|
|
}
|