Files
descrybe/apps/api/internal/processing/standard_fields_fill_test.go
greeneclipse 8580c996c3 Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
2026-08-09 22:47:43 +02:00

34 lines
1019 B
Go

package processing
import "testing"
func TestFillMissingStandardFields(t *testing.T) {
mapped := map[string]any{"title": "Widget"}
raw := map[string]any{"ean": "1234567890123", "manufacturer": "Acme"}
fields := []StandardFieldDef{
{Key: "title", MappingHints: []string{"name"}},
{Key: "gtin", MappingHints: []string{"ean", "upc"}},
{Key: "brand", MappingHints: []string{"manufacturer"}},
{Key: "currency", DefaultValue: "EUR"},
{Key: "color", MappingHints: []string{"colour"}},
}
out := FillMissingStandardFields(mapped, raw, fields)
if out["title"] != "Widget" {
t.Fatalf("title=%v", out["title"])
}
if out["gtin"] != "1234567890123" {
t.Fatalf("gtin=%v", out["gtin"])
}
if out["brand"] != "Acme" {
t.Fatalf("brand=%v", out["brand"])
}
if out["currency"] != "EUR" {
t.Fatalf("currency=%v", out["currency"])
}
if _, ok := out["color"]; ok {
t.Fatalf("color should stay empty, got %v", out["color"])
}
if mapped["gtin"] != nil {
t.Fatal("original mapped must not be mutated")
}
}