Files
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

100 lines
2.7 KiB
Go

package feeds
import (
"strings"
"testing"
)
func TestSuggestTarget_b2bFields(t *testing.T) {
cases := map[string]string{
"purchasePrice": "purchase_price",
"stockStatus": "availability",
"officialLink": "official_link",
"warranty": "warranty",
"service": "service",
"productModel": "product_model",
"EPRELID": "eprel_id",
"EAN": "gtin",
"name": "title",
"netMass": "weight",
"mainImage": "image_url",
}
for in, want := range cases {
if got := SuggestTarget(in); got != want {
t.Fatalf("%s: got %q want %q", in, got, want)
}
}
}
func TestNormalizeSuggestKey(t *testing.T) {
cases := map[string]string{
"EAN": "ean",
"purchasePrice": "purchaseprice",
"mainImage": "mainimage",
"EPRELID": "eprelid",
"specifications": "specifications",
}
for in, want := range cases {
got := normalizeSuggestKey(in)
if got != want {
t.Fatalf("%q: got %q want %q", in, got, want)
}
}
if leafSuggestKey("rss/channel/item/g:gtin") != "gtin" {
t.Fatalf("leaf g:gtin → %q", leafSuggestKey("rss/channel/item/g:gtin"))
}
}
func TestSuggestMappingsAliases(t *testing.T) {
schema := []SchemaField{
{Path: "EAN", FieldName: "EAN"},
{Path: "name", FieldName: "name"},
{Path: "brand", FieldName: "brand"},
{Path: "purchasePrice", FieldName: "purchasePrice"},
{Path: "stock", FieldName: "stock"},
{Path: "mainImage", FieldName: "mainImage"},
{Path: "EPRELID", FieldName: "EPRELID"},
{Path: "specifications", FieldName: "specifications"},
}
targets := []string{
"gtin", "title", "brand", "price", "purchase_price", "stock", "image_url", "eprel_id", "specs",
}
got := SuggestMappings(schema, targets)
bySrc := map[string]string{}
for _, s := range got {
bySrc[s.Source] = s.Target
}
want := map[string]string{
"EAN": "gtin",
"name": "title",
"brand": "brand",
"purchasePrice": "purchase_price",
"stock": "stock",
"mainImage": "image_url",
"EPRELID": "eprel_id",
"specifications": "specs",
}
for src, tgt := range want {
if bySrc[src] != tgt {
t.Fatalf("%s → %q, want %q (all=%v)", src, bySrc[src], tgt, bySrc)
}
}
}
func TestSuggestMappingsRespectsEnabled(t *testing.T) {
schema := []SchemaField{{Path: "EAN", FieldName: "EAN"}, {Path: "name", FieldName: "name"}}
got := SuggestMappings(schema, []string{"title"})
if len(got) != 1 || got[0].Target != "title" {
t.Fatalf("expected only title, got %#v", got)
}
}
func TestLeafSuggestKey(t *testing.T) {
if leafSuggestKey("rss/channel/item/g:gtin") != "gtin" {
t.Fatalf("got %q", leafSuggestKey("rss/channel/item/g:gtin"))
}
if !strings.Contains(normalizeSuggestKey("Foo-Bar"), "foobar") {
t.Fatal("normalize")
}
}