Add tests for non-indexed variants of indexable filter types

This commit is contained in:
armirveliaj
2025-07-08 06:04:49 -04:00
committed by Dan Christian Bogos
parent 234508a2eb
commit 986e36a31f

View File

@@ -3567,3 +3567,245 @@ func TestWeightFromDynamics2(t *testing.T) {
})
}
}
func TestFiltersPassNIString(t *testing.T) {
dDP := utils.MapStorage{
utils.AccountField: "1001",
utils.Destination: "1002",
utils.Category: "call",
}
tests := []struct {
name string
fltr *FilterRule
want bool
}{
{
name: "NIStringMatch",
fltr: &FilterRule{
Type: utils.MetaNIString,
Element: "~Category",
Values: []string{"call"},
},
want: true,
},
{
name: "NIStringNotMatch",
fltr: &FilterRule{
Type: utils.MetaNIString,
Element: "~Category",
Values: []string{"premium"},
},
want: false,
},
{
name: "NIStringMultipleValues",
fltr: &FilterRule{
Type: utils.MetaNIString,
Element: "~Account",
Values: []string{"1001", "1002", "1003"},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.fltr.CompileValues(); err != nil {
t.Fatal(err)
}
got, gotErr := tt.fltr.Pass(dDP)
if gotErr != nil {
t.Errorf("Pass() failed: %v", gotErr)
return
}
if got != tt.want {
t.Errorf("Pass() = %v, want %v", got, tt.want)
}
})
}
}
func TestFiltersPassNISuffix(t *testing.T) {
dDP := utils.MapStorage{
utils.AccountField: "1001",
utils.Destination: "+4985837291",
utils.Category: "call",
}
tests := []struct {
name string
fltr *FilterRule
want bool
}{
{
name: "MatchingNISuffix",
fltr: &FilterRule{
Type: utils.MetaNISuffix,
Element: "~Destination",
Values: []string{"91"},
},
want: true,
},
{
name: "NonMatchingSuffix",
fltr: &FilterRule{
Type: utils.MetaNISuffix,
Element: "~Account",
Values: []string{"02"},
},
want: false,
},
{
name: "NISuffixPassMultipleValues",
fltr: &FilterRule{
Type: utils.MetaNISuffix,
Element: "~Destination",
Values: []string{"3", "91", "22"},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.fltr.CompileValues(); err != nil {
t.Fatal(err)
}
got, err := tt.fltr.Pass(dDP)
if err != nil {
t.Errorf("Pass() error = %v", err)
return
}
if got != tt.want {
t.Errorf("Pass() = %v, want %v", got, tt.want)
}
})
}
}
func TestFiltersPassNIExists(t *testing.T) {
dDP := utils.MapStorage{
utils.AccountField: "1001",
utils.Destination: "1002",
utils.Category: "call",
}
tests := []struct {
name string
fltr *FilterRule
want bool
}{
{
name: "NIExistsField",
fltr: &FilterRule{
Type: utils.MetaNIExists,
Element: "~Category",
Values: []string{},
},
want: true,
},
{
name: "NonNIExistentField",
fltr: &FilterRule{
Type: utils.MetaNIExists,
Element: "~NonExistentField",
Values: []string{},
},
want: false,
},
{
name: "NIExistsAccount",
fltr: &FilterRule{
Type: utils.MetaNIExists,
Element: "~Account",
Values: []string{},
},
want: true,
},
{
name: "NIExistsDestination",
fltr: &FilterRule{
Type: utils.MetaNIExists,
Element: "~Destination",
Values: []string{},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.fltr.CompileValues(); err != nil {
t.Fatal(err)
}
got, err := tt.fltr.Pass(dDP)
if err != nil {
t.Errorf("Pass() error = %v", err)
return
}
if got != tt.want {
t.Errorf("Pass() = %v, want %v", got, tt.want)
}
})
}
}
func TestFiltersPassNIPrefix(t *testing.T) {
dDP := utils.MapStorage{
utils.AccountField: "1001",
utils.Destination: "+4985837291",
utils.Category: "call",
}
tests := []struct {
name string
fltr *FilterRule
want bool
}{
{
name: "MatchingNIPrefix",
fltr: &FilterRule{
Type: utils.MetaNIPrefix,
Element: "~Destination",
Values: []string{"+49"},
},
want: true,
},
{
name: "NonMatchingNIPrefix",
fltr: &FilterRule{
Type: utils.MetaNIPrefix,
Element: "~Account",
Values: []string{"20"},
},
want: false,
},
{
name: "NIPrefixPassMultipleValues",
fltr: &FilterRule{
Type: utils.MetaNIPrefix,
Element: "~Destination",
Values: []string{"+49", "+21", "+35"},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.fltr.CompileValues(); err != nil {
t.Fatal(err)
}
got, err := tt.fltr.Pass(dDP)
if err != nil {
t.Errorf("Pass() error = %v", err)
return
}
if got != tt.want {
t.Errorf("Pass() = %v, want %v", got, tt.want)
}
})
}
}