updated GetActions api to return negative destinations

This commit is contained in:
gezimbll
2026-01-06 09:43:45 +01:00
committed by Dan Christian Bogos
parent 40ff69ba40
commit 6695db8df7
3 changed files with 70 additions and 1 deletions

View File

@@ -713,7 +713,7 @@ func (apierSv1 *APIerSv1) GetActions(ctx *context.Context, actsId *string, reply
if bf != nil {
act.BalanceType = bf.GetType()
act.Units = strconv.FormatFloat(bf.GetValue(), 'f', -1, 64)
act.DestinationIds = bf.GetDestinationIDs().String()
act.DestinationIds = bf.GetDestinationIDs().AsPrefixedString()
act.RatingSubject = bf.GetRatingSubject()
act.SharedGroups = bf.GetSharedGroups().String()
act.BalanceWeight = strconv.FormatFloat(bf.GetWeight(), 'f', -1, 64)

View File

@@ -104,6 +104,21 @@ func StringMapFromSlice(s []string) StringMap {
return result
}
func (sm StringMap) AsPrefixedString() string {
if len(sm) == 0 {
return ""
}
res := make([]string, 0, len(sm))
for key, enabled := range sm {
if !enabled {
res = append(res, NegativePrefix+key)
} else {
res = append(res, key)
}
}
return strings.Join(res, InfieldSep)
}
func (sm StringMap) Copy(o StringMap) {
for k, v := range o {
sm[k] = v

View File

@@ -19,7 +19,9 @@ package utils
import (
"reflect"
"slices"
"sort"
"strings"
"testing"
)
@@ -519,6 +521,58 @@ func TestStringMapFromSlice(t *testing.T) {
}
func TestStringMapAsPrefixedString(t *testing.T) {
tests := []struct {
name string
input StringMap
expStr string
}{
{
name: "NormalDest",
input: StringMap{
"DEST_1001": true,
"DEST_1002": true,
},
expStr: "DEST_1001;DEST_1002",
},
{
name: "ExcludedDest",
input: StringMap{
"DEST_1003": false,
"DEST_1004": false,
},
expStr: "!DEST_1003;!DEST_1004",
},
{
name: "MixedDest",
input: StringMap{
"DEST_1001": true,
"DEST_1004": false,
},
expStr: "DEST_1001;!DEST_1004",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.input.AsPrefixedString()
gotDest := strings.Split(got, InfieldSep)
expDest := strings.Split(tt.expStr, InfieldSep)
slices.Sort(gotDest)
slices.Sort(expDest)
for i := range gotDest {
if gotDest[i] != expDest[i] {
t.Errorf("Mismatch at index %d! Expected: %s, Received: %s", i, expDest[i], gotDest[i])
}
}
})
}
}
func TestStringMapNewStringMap(t *testing.T) {
s := []string{"foo", "", "!baz", "bar"}
exp := map[string]bool{