feat: implement scenario-driven sales SOP platform
This commit is contained in:
33
codes/internal/run/engine_test.go
Normal file
33
codes/internal/run/engine_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user