package run import ( "reflect" "testing" "git.iwork-ai.com/xdc/iqudo-top1/internal/model" "gorm.io/datatypes" ) func TestGenericRuntimeSupportsDifferentDomains(t *testing.T) { tests := []struct { name string fields []model.ScenarioField input map[string]interface{} rules []model.ScenarioRule wantInput map[string]interface{} wantOutput interface{} }{ { name: "pet order", fields: []model.ScenarioField{{FieldKey: "tags", SourcePath: "order.items[*].symptom_tags[*]"}}, input: map[string]interface{}{"order": map[string]interface{}{"items": []interface{}{map[string]interface{}{"symptom_tags": []interface{}{"soft_stool"}}}}}, rules: []model.ScenarioRule{{RuleKey: "pet", Condition: datatypes.JSON([]byte(`{"field":"input.tags","operator":"exists"}`)), Actions: datatypes.JSON([]byte(`[{"operation":"set","field":"matched","value_from":"input.tags"}]`))}}, wantInput: map[string]interface{}{"tags": []interface{}{"soft_stool"}}, wantOutput: []interface{}{"soft_stool"}, }, { name: "course recommendation", fields: []model.ScenarioField{{FieldKey: "goals", SourcePath: "learner.goals[*]"}}, input: map[string]interface{}{"learner": map[string]interface{}{"goals": []interface{}{"presentation"}}}, rules: []model.ScenarioRule{{RuleKey: "course", Condition: datatypes.JSON([]byte(`{"field":"input.goals","operator":"exists"}`)), Actions: datatypes.JSON([]byte(`[{"operation":"set","field":"matched","value_from":"input.goals"}]`))}}, wantInput: map[string]interface{}{"goals": []interface{}{"presentation"}}, wantOutput: []interface{}{"presentation"}, }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { mapped := mapScenarioInput(test.fields, test.input) if !reflect.DeepEqual(mapped, test.wantInput) { t.Fatalf("mapped=%#v", mapped) } derived, _, err := applyScenarioRules(test.rules, mapped) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(derived["matched"], test.wantOutput) { t.Fatalf("derived=%#v", derived) } }) } }