From 229061e4f2897bfcd2108b4bd9df33b3bc4ac783 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 26 Jul 2019 13:39:13 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8DSkuStockUpdateBatch?= =?UTF-8?q?=E4=B8=8ESkuStockUpdateOne=E4=B8=AD=E9=94=99=E8=AF=AF=E4=BD=BF?= =?UTF-8?q?=E7=94=A8PriceString=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/shop_sku.go | 4 +- platformapi/ebaiapi/shop_sku_test.go | 59 ++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index 8431158a..f7f7a46c 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -450,7 +450,7 @@ func (a *API) SkuPriceUpdateOne(shopID string, priceInfo *ShopSkuInfo) (err erro func (a *API) SkuStockUpdateBatch(shopID string, stockList ShopSkuInfoList, skuIDType int) (opResult *BatchOpResult, err error) { params := map[string]interface{}{ KeyShopID: shopID, - stockUpdateKeyIDMap[skuIDType]: stockList.PriceString(skuIDType), + stockUpdateKeyIDMap[skuIDType]: stockList.StockString(skuIDType), } result, err := a.AccessAPI("sku.stock.update.batch", params) if err == nil { @@ -465,7 +465,7 @@ func (a *API) SkuStockUpdateOne(shopID string, stockInfo *ShopSkuInfo) (err erro skuIDType := stockInfo.GuessIDType() params := map[string]interface{}{ KeyShopID: shopID, - stockUpdateKeyIDMap[skuIDType]: stockInfo.PriceString(skuIDType), + stockUpdateKeyIDMap[skuIDType]: stockInfo.StockString(skuIDType), } _, err = a.AccessAPI("sku.stock.update.one", params) return err diff --git a/platformapi/ebaiapi/shop_sku_test.go b/platformapi/ebaiapi/shop_sku_test.go index c21b816d..bfa75db2 100644 --- a/platformapi/ebaiapi/shop_sku_test.go +++ b/platformapi/ebaiapi/shop_sku_test.go @@ -48,8 +48,8 @@ func TestSkuGetItemsByCategoryId(t *testing.T) { } func TestSkuList(t *testing.T) { - result, err := api.SkuList("102023", &SkuListParams{ - // SkuID: 15579787500720732, + result, err := api.SkuList(testShopID, &SkuListParams{ + SkuID: 156411107107487, }) if err != nil { t.Fatal(err) @@ -196,29 +196,66 @@ func TestSkuPriceUpdateBatch(t *testing.T) { } func TestSkuStockUpdateBatch(t *testing.T) { + const ( + notExistSkuID = 12345678 + existSkuID = 156406688807623 + + leftNum = 123 + ) + opResult, err := api.SkuStockUpdateBatch(testShopID, ShopSkuInfoList{ &ShopSkuInfo{ - SkuID: 156291398007698, - Stock: 2, + SkuID: notExistSkuID, + Stock: leftNum, }, &ShopSkuInfo{ - SkuID: 13121231, - Stock: 2, - }, - &ShopSkuInfo{ - SkuID: 12321, - Stock: 2, + SkuID: existSkuID, + Stock: leftNum, }, }, SkuIDTypeSkuID) t.Log(utils.Format4Output(opResult, false)) if err == nil { t.Fatal("应该要报错才对") } - if len(opResult.FailedList) != 3 { + if len(opResult.FailedList) != 1 { t.Fatal("错误列表不正确") } + + skuInfo, err := api.SkuList(testShopID, &SkuListParams{ + SkuID: existSkuID, + }) + if err != nil { + t.Fatal(err) + } + if skuInfo.List[0].LeftNum != leftNum { + t.Fatal("设置库存失败") + } } +func TestSkuStockUpdateOne(t *testing.T) { + const ( + notExistSkuID = 12345678 + existSkuID = 156406688807623 + + leftNum = 234 + ) + err := api.SkuStockUpdateOne(testShopID, &ShopSkuInfo{ + SkuID: existSkuID, + Stock: leftNum, + }) + if err != nil { + t.Fatal(err) + } + skuInfo, err := api.SkuList(testShopID, &SkuListParams{ + SkuID: existSkuID, + }) + if err != nil { + t.Fatal(err) + } + if skuInfo.List[0].LeftNum != leftNum { + t.Fatal("设置库存失败") + } +} func TestGetEbaiCatIDFromName(t *testing.T) { ebaiCatID := api.GetEbaiCatIDFromName("300280", "应季水果新鲜美味") t.Log(ebaiCatID)