67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
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",
|
||
|
|
"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"`)
|
||
|
|
ppAt := strings.Index(s, `"processed_product_id"`)
|
||
|
|
if eanAt < 0 || titleAt < 0 || attrsAt < 0 || ppAt < 0 {
|
||
|
|
t.Fatalf("missing keys in %s", s)
|
||
|
|
}
|
||
|
|
if !(eanAt < titleAt && titleAt < attrsAt && attrsAt < ppAt) {
|
||
|
|
t.Fatalf("bad key order in %s", s)
|
||
|
|
}
|
||
|
|
}
|