feat: simplify SOP to immediate-effect configuration
This commit is contained in:
39
internal/run/rules_test.go
Normal file
39
internal/run/rules_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"git.iwork-ai.com/xdc/iqudo-top1/internal/model"
|
||||
"gorm.io/datatypes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestApplyScenarioRules(t *testing.T) {
|
||||
rules := []model.ScenarioRule{{RuleKey: "r1", Condition: datatypes.JSON([]byte(`{"field":"tags","operator":"contains","value":"soft"}`)), Actions: datatypes.JSON([]byte(`[{"operation":"append","field":"symptoms","value":"soft_stool"}]`))}}
|
||||
derived, matched, err := applyScenarioRules(rules, map[string]interface{}{"tags": []interface{}{"soft"}})
|
||||
if err != nil || len(matched) != 1 || len(derived["symptoms"].([]interface{})) != 1 {
|
||||
t.Fatalf("derived=%v matched=%v err=%v", derived, matched, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyScenarioRulesSupportsValueFrom(t *testing.T) {
|
||||
rules := []model.ScenarioRule{{RuleKey: "copy_tags", Condition: datatypes.JSON([]byte(`{"field":"input_tags","operator":"exists"}`)), Actions: datatypes.JSON([]byte(`[{"operation":"append","field":"matched_symptoms","value_from":"input_tags"}]`))}}
|
||||
derived, _, err := applyScenarioRules(rules, map[string]interface{}{"input_tags": []interface{}{"soft_stool", "poor_appetite"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values, ok := derived["matched_symptoms"].([]interface{})
|
||||
if !ok || len(values) != 2 || values[0] != "soft_stool" || values[1] != "poor_appetite" {
|
||||
t.Fatalf("derived = %#v", derived)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyScenarioRulesSupportsNamespacedValueFrom(t *testing.T) {
|
||||
rules := []model.ScenarioRule{{RuleKey: "copy_tags", Condition: datatypes.JSON([]byte(`{"field":"input.input_tags","operator":"exists"}`)), Actions: datatypes.JSON([]byte(`[{"operation":"set","field":"matched_symptoms","value_from":"input.input_tags"}]`))}}
|
||||
derived, _, err := applyScenarioRules(rules, map[string]interface{}{"input_tags": []interface{}{"soft_stool"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values, ok := derived["matched_symptoms"].([]interface{})
|
||||
if !ok || len(values) != 1 || values[0] != "soft_stool" {
|
||||
t.Fatalf("derived = %#v", derived)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user