Files
descrybe/apps/api/internal/processing/enrich_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

110 lines
2.8 KiB
Go

package processing
import (
"testing"
)
func TestEnrichMapped_gtinFromEANAndTitleFromName(t *testing.T) {
got := EnrichMapped(map[string]any{
"EAN": "3830085913912",
"name": "Bosch Fridge",
})
if got["gtin"] != "3830085913912" {
t.Fatalf("gtin=%v", got["gtin"])
}
if got["title"] != "Bosch Fridge" {
t.Fatalf("title=%v", got["title"])
}
}
func TestEnrichMapped_dropsZeroDimensions(t *testing.T) {
got := EnrichMapped(map[string]any{
"netWidth": "0",
"netHeight": "0.0",
"netDepth": 0,
"width": "595",
"title": "X",
})
if _, ok := got["netWidth"]; ok {
t.Fatalf("netWidth should be dropped: %#v", got)
}
if _, ok := got["netHeight"]; ok {
t.Fatalf("netHeight should be dropped")
}
if _, ok := got["netDepth"]; ok {
t.Fatalf("netDepth should be dropped")
}
if got["width"] != "595" {
t.Fatalf("width kept=%v", got["width"])
}
}
func TestEnrichMapped_parseNetMass(t *testing.T) {
got := EnrichMapped(map[string]any{"netMass": "12,5 kg"})
if got["net_mass"] != 12.5 {
t.Fatalf("net_mass=%v", got["net_mass"])
}
if got["net_mass_unit"] != "kg" {
t.Fatalf("unit=%v", got["net_mass_unit"])
}
if got["weight"] != "12.5 kg" {
t.Fatalf("weight=%v", got["weight"])
}
}
func TestEnrichMapped_stockStatusToAvailability(t *testing.T) {
cases := map[string]string{
"In Stock": AvailabilityInStock,
"na zalogi": AvailabilityInStock,
"Out of stock": AvailabilityOutOfStock,
"pre-order": AvailabilityPreorder,
"backorder": AvailabilityBackorder,
"limited": AvailabilityLimited,
}
for in, want := range cases {
got := EnrichMapped(map[string]any{"stockStatus": in})
if got["availability"] != want {
t.Fatalf("%q -> %v want %s", in, got["availability"], want)
}
}
}
func TestEnrichMapped_stripEmptyCDATAAndHTML(t *testing.T) {
got := EnrichMapped(map[string]any{
"specifications": "<![CDATA[]]>",
"description": "<p></p><br/>",
"notes": "<![CDATA[<p>Real specs</p>]]>",
"EPRELID": "",
"mainImage": " ",
})
if _, ok := got["specifications"]; ok {
t.Fatalf("empty CDATA specs should be removed")
}
if _, ok := got["description"]; ok {
t.Fatalf("empty HTML description should be removed")
}
if _, ok := got["EPRELID"]; ok {
t.Fatalf("empty EPRELID should not be invented/kept")
}
if _, ok := got["mainImage"]; ok {
t.Fatalf("blank mainImage should be removed")
}
if got["notes"] == "" {
t.Fatalf("non-empty CDATA HTML should remain")
}
}
func TestEnrichMapped_preservesRawInput(t *testing.T) {
src := map[string]any{"netWidth": "0", "EAN": "1"}
_ = EnrichMapped(src)
if src["netWidth"] != "0" {
t.Fatalf("source mutated: %#v", src)
}
}
func TestMapStockStatus_unknown(t *testing.T) {
if MapStockStatus("maybe later") != "" {
t.Fatal("expected empty for unknown")
}
}