2026-08-16 16:57:36 +02:00
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" )
}
2026-08-17 00:39:25 +02:00
if ! categoryEnhancePromptMapOK ( want ) {
2026-08-16 16:57:36 +02:00
t . Fatal ( "canonical map should be OK" )
}
legacy := company . LangPromptMap { "sl" : "<H2>legacy HTML marketing</H2>" }
2026-08-17 00:39:25 +02:00
if categoryEnhancePromptMapOK ( legacy ) {
2026-08-16 16:57:36 +02:00
t . Fatal ( "legacy HTML must need repair" )
}
slOnly := company . LangPromptMap { "sl" : tpl }
2026-08-17 00:39:25 +02:00
if ! categoryEnhancePromptMapOK ( slOnly ) {
2026-08-16 16:57:36 +02:00
t . Fatal ( "sl-only repaired map should be OK (idempotent)" )
}
starOnly := company . LangPromptMap { company . LangPromptAny : tpl }
2026-08-17 00:39:25 +02:00
if ! categoryEnhancePromptMapOK ( starOnly ) {
2026-08-16 16:57:36 +02:00
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 )
}
}
2026-08-17 00:39:25 +02:00
if ! strings . Contains ( strings . ToLower ( tpl ), "never brand-only" ) {
t . Fatal ( "Title section must forbid brand-only names" )
}
2026-08-16 16:57:36 +02:00
if a1CompanyID == "" || platformDemoCompanyName == "" {
t . Fatal ( "missing company target constants" )
}
}
2026-08-17 00:39:25 +02:00
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 )
}
}