This commit is contained in:
2026-08-16 16:57:36 +02:00
parent 96f8c1115c
commit 532d439c41
106 changed files with 10147 additions and 494 deletions
+35
View File
@@ -54,3 +54,38 @@ func TestBuildMappedDataFromV1ItemOmitsEmptyNulls(t *testing.T) {
t.Fatal("EAN-only must not count as content")
}
}
func TestExtractProductImages_promotesMoreimagesWhenMainEmpty(t *testing.T) {
main, more := ExtractProductImages(map[string]any{
"main_image": "",
"moreimages": "https://cdn.example.com/a.jpg,https://cdn.example.com/b.jpg",
}, nil)
if main != "https://cdn.example.com/a.jpg" {
t.Fatalf("main=%q", main)
}
if len(more) != 1 || more[0] != "https://cdn.example.com/b.jpg" {
t.Fatalf("more=%v", more)
}
}
func TestExtractProductImages_imagesStringSliceAndSrcObjects(t *testing.T) {
main, more := ExtractProductImages(map[string]any{
"images": []string{
"https://cdn.example.com/main.jpg",
"https://cdn.example.com/2.jpg",
},
}, nil)
if main != "https://cdn.example.com/main.jpg" || len(more) != 1 || more[0] != "https://cdn.example.com/2.jpg" {
t.Fatalf("string slice main=%q more=%v", main, more)
}
main, more = ExtractProductImages(map[string]any{
"images": []any{
map[string]any{"src": "https://cdn.example.com/from-src.jpg"},
map[string]any{"src": "https://cdn.example.com/from-src-2.jpg"},
},
}, nil)
if main != "https://cdn.example.com/from-src.jpg" || len(more) != 1 || more[0] != "https://cdn.example.com/from-src-2.jpg" {
t.Fatalf("src objects main=%q more=%v", main, more)
}
}