- 修复SkuStockUpdateBatch与SkuStockUpdateOne中错误使用PriceString的bug

This commit is contained in:
gazebo
2019-07-26 13:39:13 +08:00
parent e34ffd277f
commit 229061e4f2
2 changed files with 50 additions and 13 deletions

View File

@@ -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

View File

@@ -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)