package engine import ( "testing" "aiaa-notification-service/internal/model" ) func TestPickEventRuleExact(t *testing.T) { rules := []model.Rule{ {ID: 1, Event: "trade.*", Enabled: 1}, {ID: 2, Event: "trade.open", Enabled: 1}, } got := PickEventRule("trade.open", rules) if got == nil || got.ID != 2 { t.Fatalf("want exact id=2, got %#v", got) } } func TestPickEventRuleWildcard(t *testing.T) { rules := []model.Rule{ {ID: 1, Event: "trade.*", Enabled: 1}, } got := PickEventRule("trade.close", rules) if got == nil || got.Event != "trade.*" { t.Fatalf("want trade.*, got %#v", got) } if PickEventRule("order.open", rules) != nil { t.Fatal("trade.* must not match order.open") } } func TestPickEventRuleMoreSpecificWildcardWins(t *testing.T) { rules := []model.Rule{ {ID: 1, Event: "*", Enabled: 1}, {ID: 2, Event: "trade.*", Enabled: 1}, } got := PickEventRule("trade.open", rules) if got == nil || got.ID != 2 { t.Fatalf("want trade.* id=2, got %#v", got) } } func TestPickEventRuleSkipsDisabled(t *testing.T) { rules := []model.Rule{ {ID: 1, Event: "trade.*", Enabled: 0}, {ID: 2, Event: "*", Enabled: 1}, } got := PickEventRule("trade.open", rules) if got == nil || got.ID != 2 { t.Fatalf("want * id=2, got %#v", got) } } func TestPickEventRuleNoMatch(t *testing.T) { rules := []model.Rule{ {ID: 1, Event: "trade.open", Enabled: 1}, } if PickEventRule("trade.close", rules) != nil { t.Fatal("expected no match") } }