40 lines
2.0 KiB
Go
40 lines
2.0 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 TestDefaultMigrationRecognizesMixedLegacyEnglishWithoutTouchingCustom(t *testing.T) {
|
|
current := aiprompts.DefaultCategoryFormula("", "High chairs")
|
|
old := aiprompts.PriorDefaultCategoryFormula("", "High chairs")
|
|
seo := aiprompts.PreviousSEODefaultCategoryFormula("", "High chairs")
|
|
variants := []aiprompts.CategoryFormulaDefaults{current, seo, old, aiprompts.LegacyDefaultCategoryFormula("", "High chairs")}
|
|
mixed := strings.Replace(current.Overlay,
|
|
aiprompts.DescriptionSectionInstructions(current.Overlay),
|
|
aiprompts.DescriptionSectionInstructions(old.Overlay), 1)
|
|
if !isMixedBuiltInEnglishPrompt(mixed, variants) {
|
|
t.Fatal("old English five-section mixed default was not recognized")
|
|
}
|
|
cache := map[string]*defaultTranslation{
|
|
catalog.DefaultPromptHash(current.Overlay): {Source: current.Overlay, Values: company.LangPromptMap{"en": current.Overlay}},
|
|
catalog.DefaultPromptHash(old.Overlay): {Source: old.Overlay, Values: company.LangPromptMap{"en": old.Overlay}},
|
|
}
|
|
if !isKnownBuiltInVariantSet(company.LangPromptMap{"en": mixed}, variants, cache) {
|
|
t.Fatal("mixed, unedited platform default was flagged custom")
|
|
}
|
|
bad := strings.Replace(mixed, "--- Meta ---", "--- Meta ---\nUse my shop's custom brand voice", 1)
|
|
if isKnownBuiltInVariantSet(company.LangPromptMap{"en": bad}, variants, cache) {
|
|
t.Fatal("custom tenant meta text must remain protected")
|
|
}
|
|
a1 := company.LangPromptMap{"sl": "A1 custom Slovenian naming, meta, and description", "en": mixed}
|
|
changed := replaceKnownBuiltInLocales(a1, variants, cache)
|
|
if changed != 1 || a1["sl"] != "A1 custom Slovenian naming, meta, and description" || a1["en"] != current.Overlay {
|
|
t.Fatalf("A1 locale migration touched custom data: changed=%d, en=%q, sl=%q", changed, a1["en"], a1["sl"])
|
|
}
|
|
}
|