This commit is contained in:
2026-08-16 16:57:36 +02:00
parent 96f8c1115c
commit 532d439c41
106 changed files with 10147 additions and 494 deletions
+58 -1
View File
@@ -76,7 +76,7 @@ func TestProjectV1ProcessJobItemsPartial(t *testing.T) {
"processed_product_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"raw_product_id": "cccccccc-cccc-cccc-cccc-cccccccccccc",
"status": "processed",
"title": "T", "meta_title": "MT",
"title": "T", "name": "T", "meta_title": "MT",
"description": "D", "attributes": map[string]any{"brand": "X"},
"main_image": "https://example.com/a.jpg", "more_images": []string{"https://example.com/b.jpg"},
"eprel": nil, "category": "cat", "category_name": "Cat",
@@ -91,6 +91,9 @@ func TestProjectV1ProcessJobItemsPartial(t *testing.T) {
if got["title"] != "T" || got["ean"] != "123" {
t.Fatalf("got=%v", got)
}
if got["name"] != "T" {
t.Fatalf("name dual-mode alias missing or mismatched: %v", got)
}
if _, ok := got["attributes"]; ok {
t.Fatalf("attributes should be projected out: %v", got)
}
@@ -108,6 +111,23 @@ func TestProjectV1ProcessJobItemsPartial(t *testing.T) {
}
}
func TestProjectV1ProcessJobItemsTitleDerivesName(t *testing.T) {
items := []V1ProcessJobItem{{
"ean": "123", "id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"status": "processed", "title": "OnlyTitle", "meta_title": "MT",
}}
out := ProjectV1ProcessJobItems("title", items)
if len(out) != 1 {
t.Fatalf("len=%d", len(out))
}
if out[0]["title"] != "OnlyTitle" {
t.Fatalf("title=%v", out[0]["title"])
}
if out[0]["name"] != "OnlyTitle" {
t.Fatalf("name should mirror title when absent: %v", out[0]["name"])
}
}
func TestV1PlainDescriptionStandalone(t *testing.T) {
got := v1PlainDescription("Line1<br>Line2 &amp; ok")
if strings.Contains(got, "<") {
@@ -118,6 +138,43 @@ func TestV1PlainDescriptionStandalone(t *testing.T) {
}
}
func TestV1PlainDescriptionEdgeCases(t *testing.T) {
nbsp := "\u00a0"
cases := []struct {
name string
in string
want string
}{
{name: "empty", in: "", want: ""},
{name: "whitespace", in: " \n\t ", want: ""},
{name: "plain", in: "Hello world", want: "Hello world"},
{name: "html_br", in: "Hello<br>World<br/>&amp; more</p><b>bold</b>", want: "Hello\nWorld\n& more\nbold"},
{name: "one_element_json_array_html", in: `["Hello<br>World"]`, want: "Hello\nWorld"},
{name: "multi_element_array", in: `["Para one.", "Para <b>two</b>."]`, want: "Para one.\nPara two."},
{name: "nested_array", in: `[["inner<br>x"]]`, want: "inner\nx"},
{name: "json_quoted_string", in: `"Plain &amp; quoted"`, want: "Plain & quoted"},
{name: "empty_array", in: `[]`, want: ""},
{name: "array_with_nulls", in: `[null, "keep", null, ""]`, want: "keep"},
{name: "array_with_object_ignored", in: `[{"text":"x"}, "ok"]`, want: "ok"},
{name: "invalid_bracket_text", in: `[not json`, want: "[not json"},
{name: "nbsp_and_entities", in: "A" + nbsp + "B&nbsp;C", want: "A B C"},
{name: "literal_unicode_escape", in: `A\u00a0B`, want: "A B"},
{name: "double_encoded_array", in: `"[\"Hello<br>World\"]"`, want: "Hello\nWorld"},
{name: "whitespace_around_array", in: " [\" spaced \"] ", want: "spaced"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := v1PlainDescription(tc.in)
if got != tc.want {
t.Fatalf("in=%q got=%q want=%q", tc.in, got, tc.want)
}
if strings.Contains(got, "<") {
t.Fatalf("html left: %q", got)
}
})
}
}
func TestApplyV1ProcessItemIDsDualMode(t *testing.T) {
processed := mustParseTestUUID(t, "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")
raw := mustParseTestUUID(t, "cccccccc-cccc-cccc-cccc-cccccccccccc")