fixes
This commit is contained in:
1 parent
43cfaa0411
commit
3b0d692839
7 files changed
+341
-136
No files matched your search
@@ -143,3 +143,118 @@ func TestNormalizeA1LegacyStructuredSEO(t *testing.T) {
|
||||
t.Fatal("not repeatable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1MissingDescriptionJSON(t *testing.T) {
|
||||
for _, source := range []string{"", " ", "null", "{}", `{"metaDescription":"140 znakov"}`, `{"sections":null,"metaTitle":"Custom"}`} {
|
||||
result, changed, err := NormalizeA1DescriptionTemplate(source)
|
||||
if err != nil || changed != 0 || result != source {
|
||||
t.Fatalf("source=%q changed=%d err=%v result=%q", source, changed, err, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1MixedOldAndNewInstructions(t *testing.T) {
|
||||
source := `<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>
|
||||
<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi Novo ime izdelka.}</p>
|
||||
|
||||
|
||||
<H2>{Izpostavi 3. drugačno in preverjeno prednost izdelka. Ne ponavljaj prejšnjih prednosti ali celotnega imena izdelka.}</H2>
|
||||
<p>{Napiši približno 100 besed o 3. samostojni, z dejanskimi podatki podprti prednosti. Ne ponavljaj informacij iz prejšnjih odstavkov. Ne uporabi celotnega novega imena izdelka. Če prednosti ni mogoče potrditi z vhodnimi podatki, je ne izmišljaj.}</p><b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij v alinejah}</li></ul>`
|
||||
cleaned, replaced := NormalizeA1RepeatedBenefits(source)
|
||||
if replaced != 3 {
|
||||
t.Fatalf("expected three old/mixed pairs replaced, got %d: %s", replaced, cleaned)
|
||||
}
|
||||
if strings.Contains(cleaned, "100 besed") || strings.Contains(cleaned, "Izpostavi en benefit") || strings.Contains(cleaned, "3. drugačno") {
|
||||
t.Fatalf("mixed legacy boilerplate survived: %s", cleaned)
|
||||
}
|
||||
if strings.Count(cleaned, "<h2>") != 2 || strings.Count(cleaned, "<ul><li>") != 1 || !strings.HasPrefix(cleaned, "<p>{") {
|
||||
t.Fatalf("expected modern SEO description with 1 intro, 2 sections and one specs list: %s", cleaned)
|
||||
}
|
||||
again, changed := NormalizeA1RepeatedBenefits(cleaned)
|
||||
if changed != 0 || again != cleaned {
|
||||
t.Fatal("mixed A1 cleanup not idempotent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1ShortLegacyAndPreservesOtherRoles(t *testing.T) {
|
||||
source := `--- Title ---
|
||||
{Ohranite naslov in pravila iz kategorije}
|
||||
--- End Title ---
|
||||
--- Description ---
|
||||
<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>
|
||||
<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi Novo ime izdelka.}</p>
|
||||
<b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij v alinejah}</li></ul>
|
||||
--- End Description ---
|
||||
--- Meta ---
|
||||
{Ohranite lasten meta prompt}
|
||||
--- End Meta ---`
|
||||
cleaned, n := NormalizeA1RepeatedBenefits(source)
|
||||
if n != 2 || strings.Count(cleaned, "<h2>") != 2 {
|
||||
t.Fatalf("expected short template upgraded, changed=%d: %s", n, cleaned)
|
||||
}
|
||||
for _, retained := range []string{"{Ohranite naslov in pravila iz kategorije}", "{Ohranite lasten meta prompt}", "--- End Description ---"} {
|
||||
if !strings.Contains(cleaned, retained) {
|
||||
t.Fatalf("custom content lost: %s", cleaned)
|
||||
}
|
||||
}
|
||||
if strings.Contains(cleaned, "100 besed") || strings.Count(cleaned, "<ul><li>") != 1 {
|
||||
t.Fatalf("duplicated spec or old paragraph remains: %s", cleaned)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1MixedStructuredTemplatePreservesMeta(t *testing.T) {
|
||||
source := `{"sections":[{"type":"h2","instructions":"Napiši Novo ime izdelka brez barve in izpostavi en benefit"},{"type":"p","instructions":"Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka"},{"type":"h2","instructions":"Izpostavi en benefit, in NE napiši Novo ime izdelka"},{"type":"p","instructions":"Napiši odstavek, ki je dolg 100 besed in VKLJUČI Novo ime izdelka"},{"type":"h2","instructions":"Izpostavi 3. drugačno in preverjeno prednost izdelka. Ne ponavljaj prejšnjih prednosti ali celotnega imena izdelka"},{"type":"p","instructions":"Napiši približno 100 besed o 3. samostojni prednosti"},{"type":"ul","instructions":"Napiši 3-10 tehničnih specifikacij v alinejah"}],"metaTitle":"A1 custom title","metaDescription":"A1 custom meta","otherField":true}`
|
||||
cleaned, count, err := NormalizeA1DescriptionTemplate(source)
|
||||
if err != nil || count != 3 {
|
||||
t.Fatalf("mixed structured template count=%d err=%v result=%s", count, err, cleaned)
|
||||
}
|
||||
for _, retained := range []string{`"metaTitle":"A1 custom title"`, `"metaDescription":"A1 custom meta"`, `"otherField":true`} {
|
||||
if !strings.Contains(cleaned, retained) {
|
||||
t.Fatalf("lost metadata %s in %s", retained, cleaned)
|
||||
}
|
||||
}
|
||||
if strings.Contains(cleaned, "100 besed") || strings.Count(cleaned, `"type":"h2"`) != 2 || strings.Count(cleaned, `"type":"ul"`) != 1 {
|
||||
t.Fatalf("did not upgrade description to SEO structure: %s", cleaned)
|
||||
}
|
||||
twice, n, err := NormalizeA1DescriptionTemplate(cleaned)
|
||||
if err != nil || n != 0 || twice != cleaned {
|
||||
t.Fatalf("structured upgrade not idempotent: n=%d err=%v", n, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1UnrelatedCustomPromptsUntouched(t *testing.T) {
|
||||
source := `<H2>{Izbira pravega izdelka}</H2><p>{Napiši opis glede na navedena dejstva, brez ugibanja.}</p>`
|
||||
actual, changed := NormalizeA1RepeatedBenefits(source)
|
||||
if actual != source || changed != 0 {
|
||||
t.Fatalf("unexpected change of custom text: %s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1LegacyEnDashSpecs(t *testing.T) {
|
||||
source := `<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2><p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>
|
||||
<b>Tehnične specifikacije</b>
|
||||
<ul><li>{Napiši 3–10 tehničnih specifikacij v alinejah}</li></ul>`
|
||||
got, count := NormalizeA1RepeatedBenefits(source)
|
||||
if count != 1 || strings.Count(got, "<ul><li>") != 1 || strings.Contains(got, "3–10 tehničnih") {
|
||||
t.Fatalf("duplicated technical specifications: %d %s", count, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1OldCableH1(t *testing.T) {
|
||||
source := `<name>{Ohrani specifičen naslov kabla}</name>
|
||||
<metaDescription>{Ohrani meta}</metaDescription>
|
||||
<H1>{Zapiši Novo_ime_izdelka}</H1>
|
||||
<H2>{Naj vključuje Novo_ime_izdelka in izpostavi en benefit}</H2>
|
||||
<p>{Nadaljuj iz naslova in napiši 100 besed o temu benefitu, ne vključuj Novo_ime_izdelka}</p>`
|
||||
got, count := NormalizeA1RepeatedBenefits(source)
|
||||
if count != 1 || strings.Contains(strings.ToLower(got), "<h1>") || strings.Contains(got, "napiši 100 besed") {
|
||||
t.Fatalf("legacy H1 not removed: %d %s", count, got)
|
||||
}
|
||||
if !strings.Contains(got, "Ohrani meta") || !strings.Contains(got, "Ohrani specifičen naslov kabla") {
|
||||
t.Fatal("overwrote category specific metadata")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user