Files
descrybe/apps/api/internal/feeds/parse_ui_mapping_test.go
T
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

54 lines
1.2 KiB
Go

package feeds
import "testing"
func TestParseUIKeyMappingArray(t *testing.T) {
raw := []any{
map[string]any{
"key": "Export/Item/ID",
"mapping": map[string]any{
"fieldName": "id",
"xpath": "Export/Item/ID",
"originalName": "ID",
},
},
map[string]any{
"key": "Export/Item/name",
"mapping": map[string]any{
"fieldName": "name",
"xpath": "Export/Item/name",
},
},
map[string]any{
"key": "Export/Item/EAN",
"mapping": map[string]any{
"fieldName": "gtin",
"xpath": "Export/Item/EAN",
},
},
}
got := parseMappings(raw)
if len(got) != 3 {
t.Fatalf("got %d mappings: %#v", len(got), got)
}
if got[0].targetKey() != "id" || got[0].sourceKey() != "Export/Item/ID" {
t.Fatalf("first=%#v", got[0])
}
path := itemPathFromMappings(raw)
if path != "Export/Item" {
t.Fatalf("item path=%q", path)
}
}
func TestItemPathFromWrappedMappings(t *testing.T) {
raw := map[string]any{
"item_path": "rss/channel/item",
"mappings": []any{
map[string]any{"source": "title", "target": "title"},
},
}
if itemPathFromMappings(raw) != "rss/channel/item" {
t.Fatalf("path=%q", itemPathFromMappings(raw))
}
}