package condition import ( "testing" "aiaa-notification-service/internal/model" ) func TestEvaluate_Empty(t *testing.T) { if !Evaluate(nil, nil) { t.Error("empty conditions should pass") } } func TestEvaluate_Exists(t *testing.T) { conds := []model.Condition{{Field: "symbol", Op: "exists"}} data := map[string]interface{}{"symbol": "BTC"} if !Evaluate(conds, data) { t.Error("symbol exists, should pass") } } func TestEvaluate_NotExists(t *testing.T) { conds := []model.Condition{{Field: "symbol", Op: "not_exists"}} data := map[string]interface{}{"price": 100} if !Evaluate(conds, data) { t.Error("symbol not exists, should pass") } } func TestEvaluate_Gt(t *testing.T) { conds := []model.Condition{{Field: "price", Op: "gt", Value: "100"}} data := map[string]interface{}{"price": float64(200)} if !Evaluate(conds, data) { t.Error("200 > 100, should pass") } } func TestEvaluate_Fail(t *testing.T) { conds := []model.Condition{ {Field: "symbol", Op: "exists"}, {Field: "price", Op: "lt", Value: "100"}, } data := map[string]interface{}{"symbol": "BTC", "price": float64(200)} if Evaluate(conds, data) { t.Error("200 < 100 is false, should fail") } } func TestEvaluate_Contains(t *testing.T) { conds := []model.Condition{{Field: "msg", Op: "contains", Value: "error"}} data := map[string]interface{}{"msg": "connection error occurred"} if !Evaluate(conds, data) { t.Error("msg contains 'error', should pass") } } func TestEvaluate_NotContains(t *testing.T) { conds := []model.Condition{{Field: "rawMessage", Op: "not_contains", Value: "启动"}} if !Evaluate(conds, map[string]interface{}{"rawMessage": "激进版AI 1.0\n市价开空"}) { t.Fatal("open text should pass") } if Evaluate(conds, map[string]interface{}{"rawMessage": "普达特量化机器人激进版启动\n账户余额:100000.00"}) { t.Fatal("startup text should be filtered") } if !Evaluate(conds, map[string]interface{}{"strategyCode": "PUTEJJ"}) { t.Fatal("missing rawMessage should pass") } }