Files

54 lines
1.2 KiB
Go
Raw Permalink Normal View History

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