100 lines
3.3 KiB
Go
100 lines
3.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 TestCategoryEnhanceTemplateHasAttrs(t *testing.T) {
|
|
t.Parallel()
|
|
tpl := aiprompts.CategoryEnhanceUserTemplate
|
|
if !strings.Contains(tpl, "{{attrs}}") {
|
|
t.Fatalf("template missing {{attrs}}: %q", tpl)
|
|
}
|
|
if !aiprompts.CategoryEnhanceHasRoleSections(tpl) {
|
|
t.Fatal("repaired template must include title/description/meta/attributes sections")
|
|
}
|
|
if !aiprompts.CategoryEnhancePromptNeedsRepair("legacy HTML prompt without attrs") {
|
|
t.Fatal("expected legacy prompt to need repair")
|
|
}
|
|
if aiprompts.CategoryEnhancePromptNeedsRepair(tpl) {
|
|
t.Fatal("canonical template should not need repair")
|
|
}
|
|
}
|
|
|
|
func TestPlatformDemoNameConstant(t *testing.T) {
|
|
t.Parallel()
|
|
if platformDemoCompanyName != "Platform Demo" {
|
|
t.Fatalf("got %q", platformDemoCompanyName)
|
|
}
|
|
}
|
|
|
|
func TestRepairedCategoryEnhancePromptMapMatchesA1Demo(t *testing.T) {
|
|
t.Parallel()
|
|
want, err := repairedCategoryEnhancePromptMap()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tpl := strings.TrimSpace(aiprompts.CategoryEnhanceUserTemplate)
|
|
if want["sl"] != tpl || want[company.LangPromptAny] != tpl {
|
|
t.Fatalf("want sl+* template, got %#v", want)
|
|
}
|
|
if !strings.Contains(tpl, "{{attrs}}") {
|
|
t.Fatal("template must include {{attrs}}")
|
|
}
|
|
}
|
|
|
|
func TestCategoryEnhancePromptMapOKAcceptsSplitOverlay(t *testing.T) {
|
|
t.Parallel()
|
|
legacy := `GPT predloga:
|
|
<name>{Napiši tip izdelka sentence case}</name>
|
|
<metaDescription>{140 znakov}</metaDescription>
|
|
<H2>{benefit}</H2>`
|
|
split := aiprompts.SplitLegacyCombinedEnhancePrompt(legacy)
|
|
m := company.LangPromptMap{"sl": split, company.LangPromptAny: split}
|
|
if !categoryEnhancePromptMapOK(m) {
|
|
t.Fatal("split overlay should count as OK")
|
|
}
|
|
}
|
|
|
|
func TestJsonbTemplatePresent(t *testing.T) {
|
|
t.Parallel()
|
|
if jsonbTemplatePresent(nil) || jsonbTemplatePresent([]byte("null")) || jsonbTemplatePresent([]byte("{}")) {
|
|
t.Fatal("empty templates must be absent")
|
|
}
|
|
if !jsonbTemplatePresent([]byte(`{"elements":[{"type":"variable","value":"brand"}]}`)) {
|
|
t.Fatal("title elements should count")
|
|
}
|
|
if !jsonbTemplatePresent([]byte(`{"sections":[{"type":"p","instructions":"x"}]}`)) {
|
|
t.Fatal("description sections should count")
|
|
}
|
|
}
|
|
|
|
func TestDeriveTitleTemplateJSON(t *testing.T) {
|
|
t.Parallel()
|
|
got := aiprompts.DeriveTitleTemplateJSON(`Napiši novo ime po formuli: "tip izdelka sentence case", "znamka s pravilno kapitalizacijo", "poln model izdelka"`)
|
|
if aiprompts.TitleTemplateNeedsRepair(got) {
|
|
t.Fatalf("derived formula still needs repair: %s", got)
|
|
}
|
|
if !strings.Contains(got, "product_type") || !strings.Contains(got, "brand") || !strings.Contains(got, "product_model") {
|
|
t.Fatalf("expected type+brand+model: %s", got)
|
|
}
|
|
fallback := aiprompts.DeriveTitleTemplateJSON("")
|
|
if !strings.Contains(fallback, "brand") || !strings.Contains(fallback, "product_model") {
|
|
t.Fatalf("fallback title template: %s", fallback)
|
|
}
|
|
if aiprompts.TitleTemplateIsBrandOnly([]byte(`{"elements":[{"type":"variable","value":"brand"}]}`)) != true {
|
|
t.Fatal("single brand stub must be brand-only")
|
|
}
|
|
}
|
|
|
|
func TestNormalizeCategoryPromptName(t *testing.T) {
|
|
t.Parallel()
|
|
if got := normalizeCategoryPromptName(" Avtosedeži in lupinice "); got != "avtosedezi in lupinice" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|