56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/aiprompts"
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/catalog"
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/company"
|
|
)
|
|
|
|
func TestSeedLanguagesAllSupported(t *testing.T) {
|
|
codes, err := langsToSeed("")
|
|
if err != nil || len(codes) != len(company.ContentLanguages) {
|
|
t.Fatalf("languages %v error %v", codes, err)
|
|
}
|
|
if _, err := langsToSeed("invalid"); err == nil {
|
|
t.Fatal("invalid language accepted")
|
|
}
|
|
}
|
|
|
|
func TestOnlyPlatformDefaultsAreEligible(t *testing.T) {
|
|
source := aiprompts.GenericCategoryFormula().Overlay
|
|
translations := company.LangPromptMap{"de": "German default"}
|
|
eligible := categoryRow{Prompts: company.LangPromptMap{"*": source}}
|
|
if !catalog.IsUntouchedDefaultPrompt(eligible.Prompts, source, translations) {
|
|
t.Fatal("default should be eligible")
|
|
}
|
|
custom := categoryRow{Prompts: company.LangPromptMap{"*": source, "de": "tenant customized the prompt"}}
|
|
if catalog.IsUntouchedDefaultPrompt(custom.Prompts, source, translations) {
|
|
t.Fatal("custom prompt must be protected")
|
|
}
|
|
}
|
|
|
|
func TestOfflineDefaultCoverage(t *testing.T) {
|
|
for _, lang := range company.ContentLanguages {
|
|
if lang == "en" {
|
|
continue
|
|
} // English uses exact source text.
|
|
text, err := aiprompts.OfflineDefaultPrompt(lang)
|
|
if err != nil || strings.TrimSpace(text) == "" {
|
|
t.Fatalf("missing bundled language %s: %v", lang, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestStructuredCustomFormulasRemainProtected(t *testing.T) {
|
|
defaultTitle := `{"mode":"formula","productType":"lowercase"}`
|
|
if !matchesDefaultFormula(defaultTitle, defaultTitle) {
|
|
t.Fatal("matching default formula not recognized")
|
|
}
|
|
if matchesDefaultFormula(`{"mode":"formula","productType":"uppercase"}`, defaultTitle) {
|
|
t.Fatal("company-authored title formula must be protected")
|
|
}
|
|
}
|