fixes
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user