Files

72 lines
1.9 KiB
Go
Raw Permalink Normal View History

2026-08-17 01:30:28 +02:00
package processing
import (
"strings"
"testing"
)
func TestEnsureReadableTitleSpacing(t *testing.T) {
t.Parallel()
cases := []struct {
in, want string
}{
{"LG Ameriški hladilnikGSXV80PZLE", "LG Ameriški hladilnik GSXV80PZLE"},
{"LG Ameriški hladilnik GSXV80PZLE", "LG Ameriški hladilnik GSXV80PZLE"},
{"Ufesa Magnum", "Ufesa Magnum"},
{"", ""},
}
for _, tc := range cases {
got := ensureReadableTitleSpacing(tc.in)
if got != tc.want {
t.Fatalf("in=%q got=%q want=%q", tc.in, got, tc.want)
}
}
}
func TestIsZeroishString_units(t *testing.T) {
t.Parallel()
for _, s := range []string{"0", "0.0", "0,00", "0,00m", "0.00cm", "0,0000kg"} {
if !isZeroishString(s) {
t.Fatalf("expected zeroish %q", s)
}
}
for _, s := range []string{"11,0000kg", "73.5", "179", "0.5"} {
if isZeroishString(s) {
t.Fatalf("expected non-zero %q", s)
}
}
}
func TestV1ProcessJobItemMarshalJSON_order(t *testing.T) {
t.Parallel()
item := V1ProcessJobItem{
"attributes": map[string]any{"brand": "LG"},
"ean": "8806091734365",
"title": "LG Fridge",
"category": "Hladilniki",
"category_id": "11",
"processed_product_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
2026-08-17 21:20:45 +02:00
"gpt_response": "should-not-ship",
2026-08-17 01:30:28 +02:00
"status": "processed",
}
b, err := item.MarshalJSON()
if err != nil {
t.Fatal(err)
}
s := string(b)
eanAt := strings.Index(s, `"ean"`)
titleAt := strings.Index(s, `"title"`)
attrsAt := strings.Index(s, `"attributes"`)
2026-08-17 21:20:45 +02:00
if eanAt < 0 || titleAt < 0 || attrsAt < 0 {
2026-08-17 01:30:28 +02:00
t.Fatalf("missing keys in %s", s)
}
2026-08-17 21:20:45 +02:00
if !(eanAt < titleAt && titleAt < attrsAt) {
2026-08-17 01:30:28 +02:00
t.Fatalf("bad key order in %s", s)
}
2026-08-17 21:20:45 +02:00
for _, leak := range []string{`"processed_product_id"`, `"gpt_response"`} {
if strings.Contains(s, leak) {
t.Fatalf("allowlist MarshalJSON must omit %s: %s", leak, s)
}
}
2026-08-17 01:30:28 +02:00
}