diff --git a/engine/stats_test.go b/engine/stats_test.go index c73ddee2c..297ff8afe 100644 --- a/engine/stats_test.go +++ b/engine/stats_test.go @@ -3535,7 +3535,7 @@ func TestStatQueueProcessEventProfileIgnoreFilters(t *testing.T) { sqPrf := &StatQueueProfile{ Tenant: "cgrates.org", ID: "SQ1", - FilterIDs: []string{"*string:~*req.Account:1001"}, + FilterIDs: []string{"*string:~*req.Stat:testStatValue"}, } sq := &StatQueue{ sqPrfl: sqPrf, @@ -3559,7 +3559,7 @@ func TestStatQueueProcessEventProfileIgnoreFilters(t *testing.T) { Tenant: "cgrates.org", ID: "SqProcessEvent", Event: map[string]interface{}{ - utils.AccountField: "1001", + "Stat": "testStatValue", }, APIOpts: map[string]interface{}{ utils.OptsStatsStatIDs: []string{"SQ1"}, @@ -3578,7 +3578,7 @@ func TestStatQueueProcessEventProfileIgnoreFilters(t *testing.T) { Tenant: "cgrates.org", ID: "SqProcessEvent", Event: map[string]interface{}{ - utils.AccountField: "1002", + "Stat": "testStatValue2", }, APIOpts: map[string]interface{}{ utils.OptsStatsStatIDs: []string{"SQ1"}, diff --git a/engine/thresholds_test.go b/engine/thresholds_test.go index cd35f89e9..2813f03d9 100644 --- a/engine/thresholds_test.go +++ b/engine/thresholds_test.go @@ -2974,3 +2974,69 @@ func TestThreholdsMatchingThresholdsForEventDoesNotPass(t *testing.T) { t.Errorf("expected: <%+v>, received: <%+v>", utils.ErrNotFound, err) } } + +func TestThresholdsProcessEventIgnoreFilters(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + data := NewInternalDB(nil, nil, true) + dm := NewDataManager(data, cfg.CacheCfg(), nil) + filterS := NewFilterS(cfg, nil, dm) + tS := NewThresholdService(dm, cfg, filterS, nil) + cfg.StatSCfg().Opts.ProfileIgnoreFilters = []*utils.DynamicBoolOpt{ + { + Value: true, + }, + } + thPrf := &ThresholdProfile{ + Tenant: "cgrates.org", + ID: "TH", + FilterIDs: []string{"*string:~*req.Threshold:testThresholdValue"}, + } + th := &Threshold{ + Tenant: "cgrates.org", + ID: "TH", + tPrfl: thPrf, + } + + if err := dm.SetThresholdProfile(context.Background(), thPrf, true); err != nil { + t.Error(err) + } + if err := dm.SetThreshold(context.Background(), th); err != nil { + t.Error(err) + } + // testing if the profile matches wtih profile ignore filters on false + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThdProcessEvent", + Event: map[string]interface{}{ + "Threshold": "testThresholdValue", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsThresholdIDs: []string{"TH"}, + utils.MetaProfileIgnoreFilters: false, + }, + } + exp := []string{"TH"} + if rcv, err := tS.processEvent(context.Background(), args.Tenant, args); err != nil { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", nil, err) + } else if !reflect.DeepEqual(rcv, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv) + } + // testing if the profile matches with wtih profile ignore filters on true + args2 := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThdProcessEvent", + Event: map[string]interface{}{ + "Threshold": "testThresholdValue2", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsThresholdIDs: []string{"TH"}, + utils.MetaProfileIgnoreFilters: true, + }, + } + exp2 := []string{"TH"} + if rcv2, err := tS.processEvent(context.Background(), args2.Tenant, args2); err != nil { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", nil, err) + } else if !reflect.DeepEqual(rcv2, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp2, rcv2) + } +}