199 lines
4.4 KiB
Go
199 lines
4.4 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("一个高级商品", 0, 0, pageSize, true)
|
|
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(ids, nil)
|
|
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 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 TestBatchAddSku(t *testing.T) {
|
|
paramList := []*CreateByUpcParam{
|
|
&CreateByUpcParam{
|
|
Upc: "6948939649102",
|
|
OutSkuId: "50001",
|
|
Price: 213,
|
|
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)
|
|
}
|
|
}
|