74 lines
2.3 KiB
Go
74 lines
2.3 KiB
Go
package catalog
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/aiprompts"
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/company"
|
|
)
|
|
|
|
func TestRepairedCategoryEnhancePromptMap(t *testing.T) {
|
|
t.Parallel()
|
|
want, err := repairedCategoryEnhancePromptMap()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tpl := strings.TrimSpace(aiprompts.CategoryEnhanceUserTemplate)
|
|
if want["sl"] != tpl {
|
|
t.Fatalf("want prompt->>'sl' = shared template")
|
|
}
|
|
if want[company.LangPromptAny] != tpl {
|
|
t.Fatalf("want * = shared template")
|
|
}
|
|
if !categoryEnhancePromptMapOK(want) {
|
|
t.Fatal("canonical map should be OK")
|
|
}
|
|
legacy := company.LangPromptMap{"sl": "<H2>legacy HTML marketing</H2>"}
|
|
if categoryEnhancePromptMapOK(legacy) {
|
|
t.Fatal("legacy HTML must need repair")
|
|
}
|
|
slOnly := company.LangPromptMap{"sl": tpl}
|
|
if !categoryEnhancePromptMapOK(slOnly) {
|
|
t.Fatal("sl-only repaired map should be OK (idempotent)")
|
|
}
|
|
starOnly := company.LangPromptMap{company.LangPromptAny: tpl}
|
|
if !categoryEnhancePromptMapOK(starOnly) {
|
|
t.Fatal("*-only repaired map should be OK (idempotent)")
|
|
}
|
|
}
|
|
|
|
func TestRepairTargetsUseSharedTemplate(t *testing.T) {
|
|
t.Parallel()
|
|
tpl := strings.TrimSpace(aiprompts.CategoryEnhanceUserTemplate)
|
|
for _, v := range []string{"name", "description", "attrs", "category", "language"} {
|
|
if !strings.Contains(tpl, "{{"+v+"}}") {
|
|
t.Fatalf("shared template missing {{%s}}", v)
|
|
}
|
|
}
|
|
if !strings.Contains(strings.ToLower(tpl), "never brand-only") {
|
|
t.Fatal("Title section must forbid brand-only names")
|
|
}
|
|
if a1CompanyID == "" || platformDemoCompanyName == "" {
|
|
t.Fatal("missing company target constants")
|
|
}
|
|
}
|
|
|
|
func TestLegacyTitleRulesFromSeedShape(t *testing.T) {
|
|
t.Parallel()
|
|
seed := `Ustvari nov opis
|
|
|
|
GPT predloga:
|
|
<name>{Napiši novo ime izdelka po formuli: "tip izdelka sentence case", "znamka s pravilno kapitalizacijo", "poln model izdelka". Ne uporabljaj vejic.}</name>
|
|
<metaDescription>{140 znakov}</metaDescription>
|
|
<H2>{benefit}</H2>`
|
|
rules := legacyTitleRules(nil, seed)
|
|
if !strings.Contains(strings.ToLower(rules), "znamka") {
|
|
t.Fatalf("expected title rules from seed, got %q", rules)
|
|
}
|
|
raw := aiprompts.DeriveTitleTemplateJSON(rules)
|
|
if aiprompts.TitleTemplateNeedsRepair(raw) {
|
|
t.Fatalf("derived title_template still needs repair: %s", raw)
|
|
}
|
|
}
|