feat: simplify SOP to immediate-effect configuration
This commit is contained in:
44
internal/knowledge/content_test.go
Normal file
44
internal/knowledge/content_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package knowledge
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseContentAcceptsLegacyStandardCopy(t *testing.T) {
|
||||
content, err := ParseContent([]byte(`{"standard_copy":"请说明情况","risk_note":"必要时转诊"}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(content.CopyTemplates) != 1 || content.CopyTemplates[0].ID != "default" || content.StandardCopy != "请说明情况" {
|
||||
t.Fatalf("unexpected legacy content: %#v", content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateReferencesRejectsUnknownScenarioField(t *testing.T) {
|
||||
content, err := ParseContent([]byte(`{"fields":[{"key":"symptom","name":"症状","source_field":"pet_symptom"}],"copy_templates":[{"id":"copy","title":"说明","content":"{{card.symptom}}"}]}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ValidateReferences(content, map[string]bool{"pet_name": true}); err == nil {
|
||||
t.Fatal("ValidateReferences() error = nil, want unknown source field error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateReferencesRejectsUnknownTemplateField(t *testing.T) {
|
||||
content, err := ParseContent([]byte(`{"fields":[{"key":"symptom","name":"症状"}],"copy_templates":[{"id":"copy","title":"说明","content":"{{input.pet_name}} {{card.disease}}"}]}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ValidateReferences(content, map[string]bool{"pet_name": true}); err == nil {
|
||||
t.Fatal("ValidateReferences() error = nil, want unknown knowledge field error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderResolvesInputAndCardFields(t *testing.T) {
|
||||
content, err := ParseContent([]byte(`{"fields":[{"key":"symptom","name":"症状","value":"未明确","source_field":"symptom"},{"key":"disease","name":"可能疾病","value":"需要医生评估"}],"copy_templates":[{"id":"copy","title":"说明","content":"{{input.pet_name}}出现{{card.symptom}},{{card.disease}}。{{input.pet_age}}岁。"}]}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
copies := Render(content, map[string]interface{}{"pet_name": "团子", "symptom": "呕吐", "pet_age": 3})
|
||||
if len(copies) != 1 || copies[0].Content != "团子出现呕吐,需要医生评估。3岁。" {
|
||||
t.Fatalf("rendered copies = %#v", copies)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user