fixes
This commit is contained in:
@@ -88,15 +88,25 @@ func TestSanitizeProductAttributes(t *testing.T) {
|
||||
if _, ok := got["netwidth"]; ok {
|
||||
t.Fatalf("alias netwidth should collapse to width: %v", got)
|
||||
}
|
||||
dropped := SanitizeProductAttributes(map[string]any{
|
||||
"brand": "XIAOMI",
|
||||
"product_model": "6941948703193",
|
||||
})
|
||||
if _, ok := dropped["product_model"]; ok {
|
||||
t.Fatalf("barcode-like product_model must be dropped: %v", dropped)
|
||||
}
|
||||
if dropped["brand"] != "XIAOMI" {
|
||||
t.Fatalf("brand=%v", dropped["brand"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterAttributesByAllowed(t *testing.T) {
|
||||
in := map[string]any{
|
||||
"brand": "Ostalo",
|
||||
"zavora": "Mehanska",
|
||||
"brand": "Ostalo",
|
||||
"zavora": "Mehanska",
|
||||
"vzmetenje": "Spredaj",
|
||||
"nosilnost": "40 kg",
|
||||
"width": "0.6 m",
|
||||
"width": "0.6 m",
|
||||
}
|
||||
allowed := map[string]struct{}{
|
||||
"nosilnost": {},
|
||||
@@ -121,6 +131,154 @@ func TestFilterAttributesByAllowed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttrsForEnhance_cat28DropsZavora(t *testing.T) {
|
||||
attrs := map[string]any{
|
||||
"brand": "Ostalo",
|
||||
"product_model": "W53070",
|
||||
"zavora": "Mehanska in elektricna",
|
||||
"vzmetenje": "Spredaj in zadaj",
|
||||
"nosilnost": "40 kg",
|
||||
}
|
||||
// Cat 28 TV mounts: barva/nosilnost — not motorcycle specs.
|
||||
allowed := map[string]struct{}{
|
||||
"barva": {},
|
||||
"nosilnost": {},
|
||||
}
|
||||
got := AttrsForEnhance(attrs, allowed)
|
||||
if got["brand"] != "Ostalo" || got["product_model"] != "W53070" {
|
||||
t.Fatalf("core keys missing: %v", got)
|
||||
}
|
||||
if got["nosilnost"] != "40 kg" {
|
||||
t.Fatalf("category key missing: %v", got)
|
||||
}
|
||||
if _, ok := got["zavora"]; ok {
|
||||
t.Fatalf("zavora must not reach enhance: %v", got)
|
||||
}
|
||||
if _, ok := got["vzmetenje"]; ok {
|
||||
t.Fatalf("vzmetenje must not reach enhance: %v", got)
|
||||
}
|
||||
user := ProductEnhanceUser("Nosilci za TV", "NOSILEC W53070", "", got)
|
||||
if strings.Contains(strings.ToLower(user), "zavora") {
|
||||
t.Fatalf("enhance user must not mention zavora:\n%s", user)
|
||||
}
|
||||
if !strings.Contains(user, "Ostalo") || !strings.Contains(user, "W53070") {
|
||||
t.Fatalf("enhance user should keep brand/model:\n%s", user)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttrsForEnhance_emptyAllowlistCoreOnly(t *testing.T) {
|
||||
got := AttrsForEnhance(map[string]any{
|
||||
"brand": "Ostalo",
|
||||
"zavora": "Mehanska",
|
||||
}, map[string]struct{}{})
|
||||
if got["brand"] != "Ostalo" {
|
||||
t.Fatalf("brand=%v", got["brand"])
|
||||
}
|
||||
if _, ok := got["zavora"]; ok {
|
||||
t.Fatalf("empty allowlist should drop junk: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttrsForEnhance_copiesEPRELEnergyClass(t *testing.T) {
|
||||
t.Parallel()
|
||||
attrs := map[string]any{
|
||||
"brand": "Bosch",
|
||||
"eprel_energy_class": "C",
|
||||
}
|
||||
ensureEnergyClassFromEPREL(attrs)
|
||||
got := AttrsForEnhance(attrs, map[string]struct{}{})
|
||||
if got["energy_class"] != "C" {
|
||||
t.Fatalf("energy_class=%v want C (from eprel_energy_class); attrs=%v", got["energy_class"], got)
|
||||
}
|
||||
if _, ok := got["eprel_energy_class"]; ok {
|
||||
t.Fatalf("eprel_energy_class must be stripped by AttrsForEnhance: %v", got)
|
||||
}
|
||||
// Do not overwrite an existing energy_class.
|
||||
attrs2 := map[string]any{
|
||||
"energy_class": "A",
|
||||
"eprel_energy_class": "C",
|
||||
}
|
||||
ensureEnergyClassFromEPREL(attrs2)
|
||||
if attrs2["energy_class"] != "A" {
|
||||
t.Fatalf("existing energy_class overwritten: %v", attrs2["energy_class"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttrsForPersist_tvMountDropsJunkKeepsEPREL(t *testing.T) {
|
||||
attrs := map[string]any{
|
||||
"name": "TV Mount",
|
||||
"description": "html",
|
||||
"brand": "Ostalo",
|
||||
"product_model": "W53070",
|
||||
"zavora": "Mehanska in elektricna",
|
||||
"vzmetenje": "Spredaj in zadaj",
|
||||
"nosilnost": "40 kg",
|
||||
"eprel_id": "12345",
|
||||
"eprel_label": "https://eprel.example/label",
|
||||
}
|
||||
allowed := map[string]struct{}{
|
||||
"barva": {},
|
||||
"nosilnost": {},
|
||||
}
|
||||
got := AttrsForPersist(attrs, allowed)
|
||||
if _, ok := got["name"]; ok {
|
||||
t.Fatalf("reserved name must be stripped: %v", got)
|
||||
}
|
||||
if got["brand"] != "Ostalo" || got["product_model"] != "W53070" {
|
||||
t.Fatalf("core keys missing: %v", got)
|
||||
}
|
||||
if got["nosilnost"] != "40 kg" {
|
||||
t.Fatalf("category key missing: %v", got)
|
||||
}
|
||||
if _, ok := got["zavora"]; ok {
|
||||
t.Fatalf("zavora must not be stored: %v", got)
|
||||
}
|
||||
if _, ok := got["vzmetenje"]; ok {
|
||||
t.Fatalf("vzmetenje must not be stored: %v", got)
|
||||
}
|
||||
if got["eprel_id"] != "12345" || got["eprel_label"] != "https://eprel.example/label" {
|
||||
t.Fatalf("eprel keys must persist for poll projection: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunSteps_persistsCategoryAllowlist(t *testing.T) {
|
||||
e := &Engine{}
|
||||
in := ProductInput{
|
||||
GTIN: "8712285326882",
|
||||
Name: "NOSILEC W53070",
|
||||
Mapped: map[string]any{
|
||||
"name": "NOSILEC W53070",
|
||||
"category": "28",
|
||||
"brand": "Ostalo",
|
||||
"specifications": map[string]any{
|
||||
"productmodel": "W53070",
|
||||
"zavora": "Mehanska",
|
||||
"vzmetenje": "Spredaj",
|
||||
"nosilnost": "40 kg",
|
||||
},
|
||||
},
|
||||
CategoryAttrKeys: map[string]map[string]struct{}{
|
||||
"28": {"nosilnost": {}, "barva": {}},
|
||||
},
|
||||
}
|
||||
out, err := e.RunSteps(context.Background(), "co", in, "attributes", nil, StepPolicy{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out.ProcessedAttributes["brand"] != "Ostalo" {
|
||||
t.Fatalf("brand=%v", out.ProcessedAttributes["brand"])
|
||||
}
|
||||
if out.ProcessedAttributes["nosilnost"] != "40 kg" {
|
||||
t.Fatalf("nosilnost=%v", out.ProcessedAttributes)
|
||||
}
|
||||
if _, ok := out.ProcessedAttributes["zavora"]; ok {
|
||||
t.Fatalf("zavora must not be stored: %v", out.ProcessedAttributes)
|
||||
}
|
||||
if _, ok := out.ProcessedAttributes["vzmetenje"]; ok {
|
||||
t.Fatalf("vzmetenje must not be stored: %v", out.ProcessedAttributes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1PlainDescription(t *testing.T) {
|
||||
got := v1PlainDescription("Hello<br>World<br/>& more</p><b>bold</b>")
|
||||
if strings.Contains(got, "<") {
|
||||
|
||||
Reference in New Issue
Block a user