update
This commit is contained in:
@@ -90,6 +90,50 @@ func TestSanitizeProductAttributes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterAttributesByAllowed(t *testing.T) {
|
||||
in := map[string]any{
|
||||
"brand": "Ostalo",
|
||||
"zavora": "Mehanska",
|
||||
"vzmetenje": "Spredaj",
|
||||
"nosilnost": "40 kg",
|
||||
"width": "0.6 m",
|
||||
}
|
||||
allowed := map[string]struct{}{
|
||||
"nosilnost": {},
|
||||
"barva": {},
|
||||
}
|
||||
got := FilterAttributesByAllowed(in, allowed)
|
||||
if got["brand"] != "Ostalo" || got["width"] != "0.6 m" {
|
||||
t.Fatalf("core keys missing: %v", got)
|
||||
}
|
||||
if got["nosilnost"] != "40 kg" {
|
||||
t.Fatalf("allowed key missing: %v", got)
|
||||
}
|
||||
if _, ok := got["zavora"]; ok {
|
||||
t.Fatalf("junk spec should be dropped: %v", got)
|
||||
}
|
||||
if _, ok := got["vzmetenje"]; ok {
|
||||
t.Fatalf("junk spec should be dropped: %v", got)
|
||||
}
|
||||
unchanged := FilterAttributesByAllowed(in, nil)
|
||||
if unchanged["zavora"] != "Mehanska" {
|
||||
t.Fatalf("nil allowlist should keep all: %v", unchanged)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1PlainDescription(t *testing.T) {
|
||||
got := v1PlainDescription("Hello<br>World<br/>& more</p><b>bold</b>")
|
||||
if strings.Contains(got, "<") {
|
||||
t.Fatalf("html should be stripped: %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "Hello") || !strings.Contains(got, "World") || !strings.Contains(got, "bold") {
|
||||
t.Fatalf("got=%q", got)
|
||||
}
|
||||
if !strings.Contains(got, "& more") {
|
||||
t.Fatalf("expected unescaped amp: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillMissingFields_brandAndDims(t *testing.T) {
|
||||
m := FillMissingFields(map[string]any{
|
||||
"name": "Nike Air 30x20x10 cm",
|
||||
|
||||
Reference in New Issue
Block a user