feat: 保存并展示 PDD 店铺与价格采样信息 (#31)
This commit is contained in:
@@ -155,7 +155,7 @@ func TestCreatePddProduct_删除后重新创建复活且清空采集结果(t *te
|
||||
url := "https://mobile.yangkeduo.com/goods.html?goods_id=737116531267"
|
||||
|
||||
goodsID, _ := CreatePddProduct(db, url)
|
||||
if err := repository.SetCollectResult(db, goodsID, "旧标题", sampleSkusJSON); err != nil {
|
||||
if err := repository.SetCollectResult(db, goodsID, "旧标题", "", sampleSkusJSON); err != nil {
|
||||
t.Fatalf("写采集结果失败: %v", err)
|
||||
}
|
||||
before, _ := repository.GetPddProductByGoodsID(db, goodsID)
|
||||
@@ -256,8 +256,8 @@ func TestListPddProducts_规格数(t *testing.T) {
|
||||
createProduct(t, db, "100000000002") // 采到 3 个
|
||||
createProduct(t, db, "100000000003") // 采到 0 个
|
||||
|
||||
repository.SetCollectResult(db, "100000000002", "有规格的", sampleSkusJSON)
|
||||
repository.SetCollectResult(db, "100000000003", "没规格的", `{"skus": []}`)
|
||||
repository.SetCollectResult(db, "100000000002", "有规格的", "", sampleSkusJSON)
|
||||
repository.SetCollectResult(db, "100000000003", "没规格的", "", `{"skus": []}`)
|
||||
|
||||
result, err := ListPddProducts(db, "", "")
|
||||
if err != nil {
|
||||
@@ -300,7 +300,7 @@ func TestListPddProducts_按采集状态筛选(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
createProduct(t, db, "100000000001")
|
||||
createProduct(t, db, "100000000002")
|
||||
repository.SetCollectResult(db, "100000000002", "已采的", sampleSkusJSON)
|
||||
repository.SetCollectResult(db, "100000000002", "已采的", "", sampleSkusJSON)
|
||||
|
||||
collected, err := ListPddProducts(db, "", model.CollectCollected)
|
||||
if err != nil {
|
||||
@@ -372,7 +372,7 @@ func TestStatusLine_四个状态都列出来(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
createProduct(t, db, "100000000001")
|
||||
createProduct(t, db, "100000000002")
|
||||
repository.SetCollectResult(db, "100000000002", "已采的", sampleSkusJSON)
|
||||
repository.SetCollectResult(db, "100000000002", "已采的", "", sampleSkusJSON)
|
||||
|
||||
result, _ := ListPddProducts(db, "", "")
|
||||
line := result.StatusLine()
|
||||
@@ -388,7 +388,7 @@ func TestStatusLine_四个状态都列出来(t *testing.T) {
|
||||
func TestGetPddProductDetail_规格表按dimensions排列(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
createProduct(t, db, "737116531267")
|
||||
repository.SetCollectResult(db, "737116531267", "西装外套三件套", sampleSkusJSON)
|
||||
repository.SetCollectResult(db, "737116531267", "西装外套三件套", "", sampleSkusJSON)
|
||||
p, _ := repository.GetPddProductByGoodsID(db, "737116531267")
|
||||
|
||||
d, err := GetPddProductDetail(db, p.ID)
|
||||
@@ -424,12 +424,55 @@ func TestGetPddProductDetail_规格表按dimensions排列(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPdd页面_显示店铺与按颜色采样标记(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
createProduct(t, db, "737116531267")
|
||||
resultJSON := `{
|
||||
"goods_id":"737116531267",
|
||||
"price_granularity":"color",
|
||||
"dimensions":[
|
||||
{"key":"color","name":"颜色分类"},
|
||||
{"key":"size","name":"尺码"}
|
||||
],
|
||||
"skus":[
|
||||
{"options":{"color":"黑色","size":"M"},"price_cent":470,
|
||||
"price_observed_at":{"color":"黑色","size":"M"},"available":true},
|
||||
{"options":{"color":"黑色","size":"2XL"},"price_cent":470,
|
||||
"price_observed_at":{"color":"黑色","size":"M"},"available":true}
|
||||
]
|
||||
}`
|
||||
repository.SetCollectResult(
|
||||
db, "737116531267", "测试商品", "测试旗舰店", resultJSON)
|
||||
|
||||
list, err := ListPddProducts(db, "", "")
|
||||
if err != nil {
|
||||
t.Fatalf("读取列表失败: %v", err)
|
||||
}
|
||||
if len(list.Rows) != 1 || list.Rows[0].ShopName != "测试旗舰店" {
|
||||
t.Fatalf("列表应显示店铺名,实际 %+v", list.Rows)
|
||||
}
|
||||
|
||||
p, _ := repository.GetPddProductByGoodsID(db, "737116531267")
|
||||
detail, err := GetPddProductDetail(db, p.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("读取详情失败: %v", err)
|
||||
}
|
||||
if detail.ShopName != "测试旗舰店" || !detail.ShowPriceSource {
|
||||
t.Errorf("详情应显示店铺和价格粒度提示,实际 shop=%q show=%v",
|
||||
detail.ShopName, detail.ShowPriceSource)
|
||||
}
|
||||
if len(detail.SKUs) != 2 || detail.SKUs[0].PriceSource != "✓ 实测" ||
|
||||
detail.SKUs[1].PriceSource != "推断" {
|
||||
t.Errorf("实测/推断标记不正确: %+v", detail.SKUs)
|
||||
}
|
||||
}
|
||||
|
||||
// dimensions 缺失时退回按 key 排序。不排的话 Go 的 map 是随机顺序,
|
||||
// 同一个商品每次刷新页面列的顺序都不一样。
|
||||
func TestGetPddProductDetail_没有dimensions时按key排序且稳定(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
createProduct(t, db, "737116531267")
|
||||
repository.SetCollectResult(db, "737116531267", "无维度信息", `{
|
||||
repository.SetCollectResult(db, "737116531267", "无维度信息", "", `{
|
||||
"skus": [{"options": {"size": "M", "color": "黑色", "style": "A"},
|
||||
"price_cent": 100, "available": true}]
|
||||
}`)
|
||||
@@ -661,7 +704,7 @@ func TestCreatePddCollectTasks_已删除的跳过(t *testing.T) {
|
||||
func TestCreatePddCollectTasks_已采集的跳过并单独计数(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
createProduct(t, db, "737116531267")
|
||||
repository.SetCollectResult(db, "737116531267", "已采完的商品", sampleSkusJSON)
|
||||
repository.SetCollectResult(db, "737116531267", "已采完的商品", "", sampleSkusJSON)
|
||||
|
||||
result, err := CreatePddCollectTasks(db, []string{"737116531267"})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user