feat: implement scenario-driven sales SOP platform

This commit is contained in:
Eric 1549169735@qq.com
2026-08-06 21:37:29 +08:00
parent 254469ab89
commit de5345607a
84 changed files with 7132 additions and 2 deletions

View File

@@ -0,0 +1,33 @@
package run
import (
"encoding/json"
"testing"
)
func TestMatchCondition(t *testing.T) {
answers := map[string]interface{}{"weight": float64(6), "urgent": true, "symptom": "持续呕吐"}
tests := []struct {
name string
rule string
want bool
}{
{name: "default", rule: `{}`, want: true},
{name: "equals", rule: `{"field":"urgent","operator":"equals","value":true}`, want: true},
{name: "greater", rule: `{"field":"weight","operator":"greater_than","value":5}`, want: true},
{name: "contains", rule: `{"field":"symptom","operator":"contains","value":"呕吐"}`, want: true},
{name: "all", rule: `{"all":[{"field":"urgent","operator":"equals","value":true},{"field":"weight","operator":"greater_than","value":5}]}`, want: true},
{name: "any false", rule: `{"any":[{"field":"urgent","operator":"equals","value":false},{"field":"weight","operator":"less_than","value":3}]}`, want: false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := matchCondition(json.RawMessage(test.rule), answers)
if err != nil {
t.Fatalf("matchCondition returned error: %v", err)
}
if got != test.want {
t.Fatalf("matchCondition() = %v, want %v", got, test.want)
}
})
}
}