f7ea2e7cf9
Motivation: 新增巴菲特激进/稳健策略(PUTEJJ/PUTEWJ)的跟单推送能力。该类信号仅有 rawMessage、无 action 字段,需按原文直接推送,并过滤启动文案、本地化时间字段。 Changes: * 支持无 action 的纯 rawMessage 信号,映射为 trade.message 事件 * 新增 not_contains 条件操作符,用于过滤启动文案 * 新增 replace 模板函数,将 Time: 替换为推送时间: * 补充巴菲特策略模板、规则与渠道配置文档
70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
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")
|
|
}
|
|
}
|