Files
descrybe/apps/api/internal/catalog/raw_v1_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

41 lines
1.2 KiB
Go

package catalog
import (
"encoding/json"
"testing"
)
func TestNormalizeGTIN(t *testing.T) {
if got := NormalizeGTIN(" 400-599-8858394 "); got != "4005998858394" {
t.Fatalf("got %q", got)
}
if got := NormalizeGTIN("SKU-ABC"); got != "SKU-ABC" {
t.Fatalf("non-digit fallback got %q", got)
}
}
func TestBuildMappedDataFromV1Item(t *testing.T) {
mapped := BuildMappedDataFromV1Item(V1ProcessItem{
EAN: "1234567890123",
Title: "Widget",
Description: "A widget",
CategoryUniqueID: "electronics",
MainImage: "https://cdn.example.com/w.jpg",
MoreImages: []any{"https://cdn.example.com/w2.jpg"},
Specifications: []map[string]any{{"key": "color", "value": "red"}},
})
if mapped["ean"] != "1234567890123" || mapped["title"] != "Widget" {
t.Fatalf("mapped=%v", mapped)
}
if mapped["category"] != "electronics" {
t.Fatalf("category=%v", mapped["category"])
}
if mapped["image_url"] != "https://cdn.example.com/w.jpg" {
t.Fatalf("image_url=%v", mapped["image_url"])
}
b, _ := json.Marshal(mapped["additional_image_urls"])
if string(b) != `["https://cdn.example.com/w2.jpg"]` {
t.Fatalf("more=%s", b)
}
}