feat: 增加蝦皮店铺名称搜索 (#182)
This commit is contained in:
@@ -503,6 +503,8 @@ func TestListShopeeProducts_店铺图片三态及组合筛选(t *testing.T) {
|
||||
{"有店铺且有图片", repository.ShopeeFilter{Shop: "has", Image: "has"}, []string{"A"}},
|
||||
{"无店铺且无图片", repository.ShopeeFilter{Shop: "missing", Image: "missing"}, []string{"D"}},
|
||||
{"组合关键词", repository.ShopeeFilter{Keyword: "店铺有图", Shop: "has", Image: "has"}, []string{"A"}},
|
||||
{"店铺名称", repository.ShopeeFilter{ShopName: "店铺 A"}, []string{"A"}},
|
||||
{"店铺名称组合", repository.ShopeeFilter{ShopName: "店铺", Shop: "has", Image: "missing"}, []string{"B"}},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@@ -525,6 +527,32 @@ func TestListShopeeProducts_店铺图片三态及组合筛选(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestListShopeeProducts_店铺名称LIKE特殊字符按原文匹配(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
for _, product := range []struct{ id, shop string }{
|
||||
{"SPECIAL", "测试%店_铺!"},
|
||||
{"PLAIN", "测试普通店铺"},
|
||||
} {
|
||||
seedShopeeProduct(t, db, product.id, product.id)
|
||||
if _, err := db.Exec(`UPDATE shopee_products SET shopee_shop_name=? WHERE goods_id=?`, product.shop, product.id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, keyword := range []string{"%", "_", "!", "%店_"} {
|
||||
result, err := ListShopeeProducts(db, repository.ShopeeFilter{ShopName: keyword}, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Total != 1 || len(result.Rows) != 1 || result.Rows[0].GoodsID != "SPECIAL" {
|
||||
t.Fatalf("店铺搜索 %q 得到 %+v,总数 %d,期望只匹配 SPECIAL", keyword, result.Rows, result.Total)
|
||||
}
|
||||
if !result.IsFiltered {
|
||||
t.Fatal("只使用店铺名称时 IsFiltered 应为 true")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseShopeePresence_三态参数(t *testing.T) {
|
||||
for _, value := range []string{"has", "missing"} {
|
||||
if got := ParseShopeePresence(value); got != value {
|
||||
|
||||
Reference in New Issue
Block a user