增加和平小店商品分类展示
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -129,7 +128,7 @@ func TestNetworkDiagnosticIncludesActivityAndFieldNamesOnly(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
|
||||
var goodsOffsets []string
|
||||
var goodsRequests []string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/embed":
|
||||
@@ -159,7 +158,9 @@ func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
|
||||
}
|
||||
case "/goods":
|
||||
offset := r.URL.Query().Get("page_begin")
|
||||
goodsOffsets = append(goodsOffsets, offset)
|
||||
category := r.URL.Query().Get("category")
|
||||
exclude := r.URL.Query().Get("excludeFields")
|
||||
goodsRequests = append(goodsRequests, category+":"+exclude+":"+offset)
|
||||
if got := r.URL.Query().Get("areaid"); got != "2" {
|
||||
t.Errorf("areaid = %q", got)
|
||||
}
|
||||
@@ -167,11 +168,18 @@ func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
|
||||
t.Errorf("page_size = %q", got)
|
||||
}
|
||||
items := []map[string]string{}
|
||||
switch offset {
|
||||
case "0":
|
||||
items = []map[string]string{{"iGoodsId": "g1", "sGoodsName": "商品一", "iPrice": "10", "iGoodsLeft": "-1"}, {"iGoodsId": "g2", "sGoodsName": "商品二", "iPrice": "20", "iGoodsLeft": "3"}}
|
||||
case "2":
|
||||
items = []map[string]string{{"iGoodsId": "g2", "sGoodsName": "重复商品", "iPrice": "20", "iGoodsLeft": "3"}, {"iGoodsId": "g3", "sGoodsName": "商品三", "iPrice": "30", "iGoodsLeft": "0"}}
|
||||
if category == "76" {
|
||||
switch offset {
|
||||
case "0":
|
||||
items = []map[string]string{{"iGoodsId": "g3", "sGoodsName": "热门商品", "iCategoryId": "76", "iPrice": "30", "iGoodsLeft": "0"}}
|
||||
}
|
||||
} else {
|
||||
switch offset {
|
||||
case "0":
|
||||
items = []map[string]string{{"iGoodsId": "g1", "sGoodsName": "商品一", "iCategoryId": "1", "iPrice": "10", "iGoodsLeft": "-1"}, {"iGoodsId": "g2", "sGoodsName": "特惠商品", "iCategoryId": "45", "iPrice": "20", "iGoodsLeft": "3"}}
|
||||
case "2":
|
||||
items = []map[string]string{{"iGoodsId": "g2", "sGoodsName": "重复商品", "iCategoryId": "45", "iPrice": "20", "iGoodsLeft": "3"}, {"iGoodsId": "g4", "sGoodsName": "商品四", "iCategoryId": "1", "iPrice": "40", "iGoodsLeft": "0"}}
|
||||
}
|
||||
}
|
||||
body, _ := json.Marshal(map[string]any{"data": map[string]any{"client_data": map[string]any{"itemsdetail": items}}})
|
||||
_, _ = w.Write(append([]byte("var recommend="), append(body, ';')...))
|
||||
@@ -201,17 +209,17 @@ func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Products() error = %v", err)
|
||||
}
|
||||
if len(products) != 3 {
|
||||
t.Fatalf("商品数量 = %d,期望 3", len(products))
|
||||
if len(products) != 4 {
|
||||
t.Fatalf("商品数量 = %d,期望 4", len(products))
|
||||
}
|
||||
if products[0].CommodityID != "g1" || products[2].CommodityID != "g3" {
|
||||
if products[0].CommodityID != "g1" || products[3].CommodityID != "g3" {
|
||||
t.Fatalf("商品顺序 = %#v", products)
|
||||
}
|
||||
if products[1].Count != 3 || products[2].Score != 30 {
|
||||
if products[1].Category != "45" || products[3].Score != 30 {
|
||||
t.Fatalf("商品字段 = %#v", products)
|
||||
}
|
||||
if got := strings.Join(goodsOffsets, ","); got != strings.Join([]string{"0", strconv.Itoa(2), strconv.Itoa(4)}, ",") {
|
||||
t.Fatalf("分页偏移 = %s", got)
|
||||
if got := strings.Join(goodsRequests, ","); got != ":iCategoryId_76:0,:iCategoryId_76:2,:iCategoryId_76:4,76::0" {
|
||||
t.Fatalf("分类分页请求 = %s", got)
|
||||
}
|
||||
assets, err := cli.XiaodianAssets("acf_uid=uid; acf_stk=stk; acf_ltkid=ltkid")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user