Files
descrybe/apps/api/internal/processing/standard_fields_fill_test.go
T

34 lines
1019 B
Go
Raw Normal View History

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")
}
}