fix
This commit is contained in:
@@ -30,6 +30,66 @@ func TestParseSpecifications_htmlAndCSV(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSpecifications_skipsGarbageAndReservedKeys(t *testing.T) {
|
||||
attrs := ParseSpecifications(map[string]any{
|
||||
":": "true",
|
||||
"zavora": "disc",
|
||||
"name": "Should not appear",
|
||||
"description": "Should not appear",
|
||||
"brand": "Vox",
|
||||
})
|
||||
if _, ok := attrs[":"]; ok {
|
||||
t.Fatalf("colon key must be dropped: %v", attrs)
|
||||
}
|
||||
if _, ok := attrs["name"]; ok {
|
||||
t.Fatalf("name must be reserved: %v", attrs)
|
||||
}
|
||||
if attrs["zavora"] != "disc" {
|
||||
t.Fatalf("zavora=%v", attrs["zavora"])
|
||||
}
|
||||
if attrs["brand"] != "Vox" {
|
||||
t.Fatalf("brand=%v", attrs["brand"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeProductAttributes(t *testing.T) {
|
||||
got := SanitizeProductAttributes(map[string]any{
|
||||
"name": "TV Mount",
|
||||
"description": "<br>html",
|
||||
"gtin": "123",
|
||||
"id": "102544",
|
||||
"purchaseprice": "10",
|
||||
"main_image": "https://x",
|
||||
":": "true",
|
||||
"brand": "Ostalo",
|
||||
"productmodel": "W53070",
|
||||
"netwidth": "0.6 m",
|
||||
"width": "0.6 m",
|
||||
"warranty": "60 mesecev",
|
||||
})
|
||||
if _, ok := got["name"]; ok {
|
||||
t.Fatalf("name must be stripped: %v", got)
|
||||
}
|
||||
if _, ok := got["description"]; ok {
|
||||
t.Fatalf("description must be stripped: %v", got)
|
||||
}
|
||||
if _, ok := got[":"]; ok {
|
||||
t.Fatalf("invalid key must be stripped: %v", got)
|
||||
}
|
||||
if got["brand"] != "Ostalo" {
|
||||
t.Fatalf("brand=%v", got["brand"])
|
||||
}
|
||||
if got["product_model"] != "W53070" {
|
||||
t.Fatalf("product_model=%v", got["product_model"])
|
||||
}
|
||||
if got["width"] != "0.6 m" {
|
||||
t.Fatalf("width=%v", got["width"])
|
||||
}
|
||||
if _, ok := got["netwidth"]; ok {
|
||||
t.Fatalf("alias netwidth should collapse to width: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillMissingFields_brandAndDims(t *testing.T) {
|
||||
m := FillMissingFields(map[string]any{
|
||||
"name": "Nike Air 30x20x10 cm",
|
||||
|
||||
Reference in New Issue
Block a user