mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update on AccountProfile from []*Balance to map[string]*Balance
This commit is contained in:
committed by
Dan Christian Bogos
parent
e285568cbe
commit
fd3d0fd8c2
@@ -29,7 +29,10 @@ import (
|
||||
// newAccountBalances constructs accountBalances
|
||||
func newAccountBalances(acnt *utils.AccountProfile,
|
||||
fltrS *engine.FilterS, ralsConns []string) (acntBlncs *accountBalances, err error) {
|
||||
blncs := utils.Balances(acnt.Balances) // will be changed with using map so OK to reference for now
|
||||
blncs := make(utils.Balances, len(acnt.Balances)) // Temporary code to pass the build please update this accordingly
|
||||
for _, bal := range acnt.Balances {
|
||||
blncs = append(blncs, bal)
|
||||
}
|
||||
blncs.Sort()
|
||||
acntBlncs = &accountBalances{blnCfgs: blncs}
|
||||
// populate typIdx
|
||||
|
||||
@@ -133,8 +133,8 @@ func testAccountSGetAccountProfile(t *testing.T) {
|
||||
ID: "1001",
|
||||
FilterIDs: []string{},
|
||||
Weight: 20,
|
||||
Balances: []*utils.Balance{
|
||||
&utils.Balance{
|
||||
Balances: map[string]*utils.Balance{
|
||||
"MonetaryBalance": &utils.Balance{
|
||||
ID: "MonetaryBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
@@ -160,7 +160,7 @@ func testAccountSGetAccountProfile(t *testing.T) {
|
||||
},
|
||||
Units: &utils.Decimal{decimal.New(14, 0)},
|
||||
},
|
||||
&utils.Balance{
|
||||
"VoiceBalance": &utils.Balance{
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
@@ -204,8 +204,8 @@ func testAccountSSettAccountProfile(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "id_test",
|
||||
Weight: 10,
|
||||
Balances: []*utils.APIBalance{
|
||||
&utils.APIBalance{
|
||||
Balances: map[string]*utils.APIBalance{
|
||||
"MonetaryBalance": &utils.APIBalance{
|
||||
ID: "MonetaryBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
@@ -231,7 +231,7 @@ func testAccountSSettAccountProfile(t *testing.T) {
|
||||
},
|
||||
Units: 14,
|
||||
},
|
||||
&utils.APIBalance{
|
||||
"VoiceBalance": &utils.APIBalance{
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
@@ -308,7 +308,7 @@ func testAccountSGetAccountProfileIDsCount(t *testing.T) {
|
||||
func testAccountSUpdateAccountProfile(t *testing.T) {
|
||||
var reply string
|
||||
apiAccPrf.Weight = 2
|
||||
apiAccPrf.Balances[0].CostIncrements[0].FixedFee = utils.Float64Pointer(123.5)
|
||||
apiAccPrf.Balances["MonetaryBalance"].CostIncrements[0].FixedFee = utils.Float64Pointer(123.5)
|
||||
if err := accSRPC.Call(utils.APIerSv1SetAccountProfile, apiAccPrf, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -126,24 +125,16 @@ func testTPAcctPrfSetTPAcctPrf(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "1001",
|
||||
Weight: 20,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
&utils.TPAccountBalance{
|
||||
ID: "MonetaryBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
Type: utils.MONETARY,
|
||||
Units: 14,
|
||||
CostIncrement: []*utils.TPBalanceCostIncrement{
|
||||
{
|
||||
FilterIDs: []string{"test_filter_id"},
|
||||
},
|
||||
},
|
||||
CostAttributes: []string{"test_cost_attribute"},
|
||||
UnitFactors: []*utils.TPBalanceUnitFactor{
|
||||
{
|
||||
FilterIDs: []string{"test_filter_id"},
|
||||
},
|
||||
},
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"MonetaryBalance": &utils.TPAccountBalance{
|
||||
ID: "MonetaryBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
Type: utils.MONETARY,
|
||||
CostIncrement: []*utils.TPBalanceCostIncrement{},
|
||||
CostAttributes: []string{},
|
||||
UnitFactors: []*utils.TPBalanceUnitFactor{},
|
||||
Units: 14,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
@@ -181,24 +172,16 @@ func testTPAcctPrfGetTPAcctPrfIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPAcctPrfUpdateTPAcctBal(t *testing.T) {
|
||||
tpAcctPrf.Balances = []*utils.TPAccountBalance{
|
||||
&utils.TPAccountBalance{
|
||||
ID: "MonetaryBalance2",
|
||||
FilterIDs: []string{},
|
||||
Weight: 12,
|
||||
Type: utils.MONETARY,
|
||||
Units: 16,
|
||||
CostIncrement: []*utils.TPBalanceCostIncrement{
|
||||
{
|
||||
FilterIDs: []string{"test_filter_id2"},
|
||||
},
|
||||
},
|
||||
CostAttributes: []string{"test_cost_attribute2"},
|
||||
UnitFactors: []*utils.TPBalanceUnitFactor{
|
||||
{
|
||||
FilterIDs: []string{"test_filter_id2"},
|
||||
},
|
||||
},
|
||||
tpAcctPrf.Balances = map[string]*utils.TPAccountBalance{
|
||||
"MonetaryBalance2": {
|
||||
ID: "MonetaryBalance2",
|
||||
FilterIDs: []string{},
|
||||
Weight: 12,
|
||||
Type: utils.MONETARY,
|
||||
CostIncrement: []*utils.TPBalanceCostIncrement{},
|
||||
CostAttributes: []string{},
|
||||
UnitFactors: []*utils.TPBalanceUnitFactor{},
|
||||
Units: 16,
|
||||
},
|
||||
}
|
||||
var result string
|
||||
@@ -216,40 +199,26 @@ func testTPAcctPrfGetTPAcctBalAfterUpdate(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "1001",
|
||||
Weight: 20,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
&utils.TPAccountBalance{
|
||||
ID: "MonetaryBalance2",
|
||||
FilterIDs: []string{},
|
||||
Weight: 12,
|
||||
Type: utils.MONETARY,
|
||||
Units: 16,
|
||||
CostIncrement: []*utils.TPBalanceCostIncrement{
|
||||
{
|
||||
FilterIDs: []string{"test_filter_id"},
|
||||
},
|
||||
},
|
||||
CostAttributes: []string{"test_cost_attribute"},
|
||||
UnitFactors: []*utils.TPBalanceUnitFactor{
|
||||
{
|
||||
FilterIDs: []string{"test_filter_id"},
|
||||
},
|
||||
},
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"MonetaryBalance2": &utils.TPAccountBalance{
|
||||
ID: "MonetaryBalance2",
|
||||
FilterIDs: []string{},
|
||||
Weight: 12,
|
||||
Type: utils.MONETARY,
|
||||
CostIncrement: []*utils.TPBalanceCostIncrement{},
|
||||
CostAttributes: []string{},
|
||||
UnitFactors: []*utils.TPBalanceUnitFactor{},
|
||||
Units: 16,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
}
|
||||
sort.Strings(revTPAcctPrf.FilterIDs)
|
||||
sort.Slice(revTPAcctPrf.Balances, func(i, j int) bool {
|
||||
return strings.Compare(revTPAcctPrf.Balances[i].Type, revTPAcctPrf.Balances[j].Type) == -1
|
||||
})
|
||||
if err := tpAcctPrfRPC.Call(utils.APIerSv1GetTPAccountProfile,
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "1001"}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sort.Strings(reply.FilterIDs)
|
||||
sort.Slice(reply.Balances, func(i, j int) bool {
|
||||
return strings.Compare(reply.Balances[i].Type, reply.Balances[j].Type) == -1
|
||||
})
|
||||
if !reflect.DeepEqual(tpAcctPrf, reply) && !reflect.DeepEqual(revTPAcctPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(tpAcctPrf), utils.ToJSON(reply))
|
||||
}
|
||||
|
||||
@@ -1632,8 +1632,8 @@ func TestLoadAccountProfiles(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "1001",
|
||||
Weight: 20,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
&utils.TPAccountBalance{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"MonetaryBalance": &utils.TPAccountBalance{
|
||||
ID: "MonetaryBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
@@ -1659,7 +1659,7 @@ func TestLoadAccountProfiles(t *testing.T) {
|
||||
},
|
||||
Units: 14,
|
||||
},
|
||||
&utils.TPAccountBalance{
|
||||
"VoiceBalance": &utils.TPAccountBalance{
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
|
||||
@@ -3520,9 +3520,10 @@ func (tps AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountPro
|
||||
aPrf, found := actPrfMap[tenID]
|
||||
if !found {
|
||||
aPrf = &utils.TPAccountProfile{
|
||||
TPid: tp.Tpid,
|
||||
Tenant: tp.Tenant,
|
||||
ID: tp.ID,
|
||||
TPid: tp.Tpid,
|
||||
Tenant: tp.Tenant,
|
||||
ID: tp.ID,
|
||||
Balances: make(map[string]*utils.TPAccountBalance),
|
||||
}
|
||||
}
|
||||
if tp.FilterIDs != utils.EmptyString {
|
||||
@@ -3601,7 +3602,7 @@ func (tps AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountPro
|
||||
unitFactors = append(unitFactors, unitFactor)
|
||||
}
|
||||
}
|
||||
aPrf.Balances = append(aPrf.Balances, &utils.TPAccountBalance{
|
||||
aPrf.Balances[tp.BalanceID] = &utils.TPAccountBalance{
|
||||
ID: tp.BalanceID,
|
||||
FilterIDs: filterIDs,
|
||||
Weight: tp.BalanceWeight,
|
||||
@@ -3612,7 +3613,7 @@ func (tps AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountPro
|
||||
CostAttributes: costAttributes,
|
||||
UnitFactors: unitFactors,
|
||||
Units: tp.BalanceUnits,
|
||||
})
|
||||
}
|
||||
}
|
||||
actPrfMap[tenID] = aPrf
|
||||
}
|
||||
@@ -3707,7 +3708,7 @@ func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *uti
|
||||
ID: tpAp.ID,
|
||||
FilterIDs: make([]string, len(tpAp.FilterIDs)),
|
||||
Weight: tpAp.Weight,
|
||||
Balances: make([]*utils.Balance, len(tpAp.Balances)),
|
||||
Balances: make(map[string]*utils.Balance, len(tpAp.Balances)),
|
||||
ThresholdIDs: make([]string, len(tpAp.ThresholdIDs)),
|
||||
}
|
||||
for i, stp := range tpAp.FilterIDs {
|
||||
@@ -3719,64 +3720,64 @@ func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *uti
|
||||
}
|
||||
}
|
||||
|
||||
for i, bal := range tpAp.Balances {
|
||||
ap.Balances[i] = &utils.Balance{
|
||||
for id, bal := range tpAp.Balances {
|
||||
ap.Balances[id] = &utils.Balance{
|
||||
ID: bal.ID,
|
||||
FilterIDs: bal.FilterIDs,
|
||||
Weight: bal.Weight,
|
||||
Blocker: bal.Blocker,
|
||||
Type: bal.Type,
|
||||
}
|
||||
if ap.Balances[i].Units, err = utils.NewDecimalFromFloat64(bal.Units); err != nil {
|
||||
if ap.Balances[id].Units, err = utils.NewDecimalFromFloat64(bal.Units); err != nil {
|
||||
return
|
||||
}
|
||||
if bal.Opts != utils.EmptyString {
|
||||
ap.Balances[i].Opts = make(map[string]interface{})
|
||||
ap.Balances[id].Opts = make(map[string]interface{})
|
||||
for _, opt := range strings.Split(bal.Opts, utils.INFIELD_SEP) { // example of opts: key1:val1;key2:val2;key3:val3
|
||||
keyValSls := utils.SplitConcatenatedKey(opt)
|
||||
if len(keyValSls) != 2 {
|
||||
err = fmt.Errorf("malformed option for ActionProfile <%s> for action <%s>", ap.TenantID(), bal.ID)
|
||||
return
|
||||
}
|
||||
ap.Balances[i].Opts[keyValSls[0]] = keyValSls[1]
|
||||
ap.Balances[id].Opts[keyValSls[0]] = keyValSls[1]
|
||||
}
|
||||
}
|
||||
if bal.CostIncrement != nil {
|
||||
ap.Balances[i].CostIncrements = make([]*utils.CostIncrement, len(bal.CostIncrement))
|
||||
ap.Balances[id].CostIncrements = make([]*utils.CostIncrement, len(bal.CostIncrement))
|
||||
for j, costIncrement := range bal.CostIncrement {
|
||||
ap.Balances[i].CostIncrements[j] = &utils.CostIncrement{
|
||||
ap.Balances[id].CostIncrements[j] = &utils.CostIncrement{
|
||||
FilterIDs: costIncrement.FilterIDs,
|
||||
}
|
||||
if costIncrement.Increment != nil {
|
||||
if ap.Balances[i].CostIncrements[j].Increment, err = utils.NewDecimalFromFloat64(*costIncrement.Increment); err != nil {
|
||||
if ap.Balances[id].CostIncrements[j].Increment, err = utils.NewDecimalFromFloat64(*costIncrement.Increment); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if costIncrement.FixedFee != nil {
|
||||
if ap.Balances[i].CostIncrements[j].FixedFee, err = utils.NewDecimalFromFloat64(*costIncrement.FixedFee); err != nil {
|
||||
if ap.Balances[id].CostIncrements[j].FixedFee, err = utils.NewDecimalFromFloat64(*costIncrement.FixedFee); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if costIncrement.RecurrentFee != nil {
|
||||
if ap.Balances[i].CostIncrements[j].RecurrentFee, err = utils.NewDecimalFromFloat64(*costIncrement.RecurrentFee); err != nil {
|
||||
if ap.Balances[id].CostIncrements[j].RecurrentFee, err = utils.NewDecimalFromFloat64(*costIncrement.RecurrentFee); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if bal.CostAttributes != nil {
|
||||
ap.Balances[i].CostAttributes = make([]string, len(bal.CostAttributes))
|
||||
ap.Balances[id].CostAttributes = make([]string, len(bal.CostAttributes))
|
||||
for j, costAttribute := range bal.CostAttributes {
|
||||
ap.Balances[i].CostAttributes[j] = costAttribute
|
||||
ap.Balances[id].CostAttributes[j] = costAttribute
|
||||
}
|
||||
}
|
||||
if bal.UnitFactors != nil {
|
||||
ap.Balances[i].UnitFactors = make([]*utils.UnitFactor, len(bal.UnitFactors))
|
||||
ap.Balances[id].UnitFactors = make([]*utils.UnitFactor, len(bal.UnitFactors))
|
||||
for j, unitFactor := range bal.UnitFactors {
|
||||
ap.Balances[i].UnitFactors[j] = &utils.UnitFactor{
|
||||
ap.Balances[id].UnitFactors[j] = &utils.UnitFactor{
|
||||
FilterIDs: unitFactor.FilterIDs,
|
||||
}
|
||||
if ap.Balances[i].UnitFactors[j].Factor, err = utils.NewDecimalFromFloat64(unitFactor.Factor); err != nil {
|
||||
if ap.Balances[id].UnitFactors[j].Factor, err = utils.NewDecimalFromFloat64(unitFactor.Factor); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -3795,7 +3796,7 @@ func AccountProfileToAPI(ap *utils.AccountProfile) (tpAp *utils.TPAccountProfile
|
||||
FilterIDs: make([]string, len(ap.FilterIDs)),
|
||||
ActivationInterval: new(utils.TPActivationInterval),
|
||||
Weight: ap.Weight,
|
||||
Balances: make([]*utils.TPAccountBalance, len(ap.Balances)),
|
||||
Balances: make(map[string]*utils.TPAccountBalance, len(ap.Balances)),
|
||||
ThresholdIDs: make([]string, len(ap.ThresholdIDs)),
|
||||
}
|
||||
for i, fli := range ap.FilterIDs {
|
||||
|
||||
@@ -7012,8 +7012,8 @@ func TestAccountProfileMdlsAsTPAccountProfile(t *testing.T) {
|
||||
ExpiryTime: "2014-07-25T15:00:00Z",
|
||||
},
|
||||
Weight: 10.0,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
@@ -7063,8 +7063,8 @@ func TestAccountProfileMdlsAsTPAccountProfileCase2(t *testing.T) {
|
||||
ActivationTime: "2014-07-24T15:00:00Z",
|
||||
},
|
||||
Weight: 10.0,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
@@ -7097,8 +7097,8 @@ func TestAPItoModelTPAccountProfile(t *testing.T) {
|
||||
ExpiryTime: "2014-07-25T15:00:00Z",
|
||||
},
|
||||
Weight: 10.0,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
@@ -7161,8 +7161,8 @@ func TestAPItoModelTPAccountProfileCase2(t *testing.T) {
|
||||
ExpiryTime: "2014-07-25T15:00:00Z",
|
||||
},
|
||||
Weight: 10.0,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR1", "FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
@@ -7189,7 +7189,7 @@ func TestAPItoModelTPAccountProfileCase2(t *testing.T) {
|
||||
}}
|
||||
sort.Strings(testStruct.FilterIDs)
|
||||
sort.Strings(testStruct.ThresholdIDs)
|
||||
sort.Strings(testStruct.Balances[0].FilterIDs)
|
||||
sort.Strings(testStruct.Balances["VoiceBalance"].FilterIDs)
|
||||
result := APItoModelTPAccountProfile(testStruct)
|
||||
if !reflect.DeepEqual(exp, result) {
|
||||
t.Errorf("Expecting: %+v,\nreceived: %+v", utils.ToJSON(exp), utils.ToJSON(result))
|
||||
@@ -7206,8 +7206,8 @@ func TestApitoAccountProfileCase2(t *testing.T) {
|
||||
ExpiryTime: "2014-07-15T14:25:00Z",
|
||||
},
|
||||
Weight: 10.0,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
@@ -7227,16 +7227,17 @@ func TestApitoAccountProfileCase2(t *testing.T) {
|
||||
ExpiryTime: time.Date(2014, 7, 15, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Weight: 10.0,
|
||||
Balances: []*utils.Balance{{
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
Type: utils.VOICE,
|
||||
Units: &utils.Decimal{decimal.New(3600000000000, 0)},
|
||||
Opts: map[string]interface{}{
|
||||
"key1": "val1",
|
||||
},
|
||||
}},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
Type: utils.VOICE,
|
||||
Units: &utils.Decimal{decimal.New(3600000000000, 0)},
|
||||
Opts: map[string]interface{}{
|
||||
"key1": "val1",
|
||||
},
|
||||
}},
|
||||
ThresholdIDs: []string{"WARN_RES1"},
|
||||
}
|
||||
result, err := APItoAccountProfile(testStruct, "")
|
||||
@@ -7258,8 +7259,8 @@ func TestApitoAccountProfileCaseTimeError(t *testing.T) {
|
||||
ExpiryTime: "test_time2",
|
||||
},
|
||||
Weight: 10.0,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
@@ -7285,8 +7286,8 @@ func TestApitoAccountProfileCaseTimeError2(t *testing.T) {
|
||||
ExpiryTime: "2014-07-15T14:25:00Z",
|
||||
},
|
||||
Weight: 10.0,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
@@ -7385,16 +7386,17 @@ func TestModelHelpersAccountProfileToAPI(t *testing.T) {
|
||||
ExpiryTime: time.Date(2014, 7, 15, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Weight: 2,
|
||||
Balances: []*utils.Balance{{
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
Type: utils.VOICE,
|
||||
Units: &utils.Decimal{decimal.New(3600000000000, 0)},
|
||||
Opts: map[string]interface{}{
|
||||
"key1": "val1",
|
||||
},
|
||||
}},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
Type: utils.VOICE,
|
||||
Units: &utils.Decimal{decimal.New(3600000000000, 0)},
|
||||
Opts: map[string]interface{}{
|
||||
"key1": "val1",
|
||||
},
|
||||
}},
|
||||
ThresholdIDs: []string{"test_thrs"},
|
||||
}
|
||||
expStruct := utils.TPAccountProfile{
|
||||
@@ -7406,8 +7408,8 @@ func TestModelHelpersAccountProfileToAPI(t *testing.T) {
|
||||
ExpiryTime: "2014-07-15T14:25:00Z",
|
||||
},
|
||||
Weight: 2,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"FLTR_RES_GR2"},
|
||||
Weight: 10,
|
||||
|
||||
@@ -158,8 +158,8 @@ func testStorDBitCRUDTPAccountProfiles(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "1001",
|
||||
Weight: 20,
|
||||
Balances: []*utils.TPAccountBalance{
|
||||
&utils.TPAccountBalance{
|
||||
Balances: map[string]*utils.TPAccountBalance{
|
||||
"MonetaryBalance": &utils.TPAccountBalance{
|
||||
ID: "MonetaryBalance",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
|
||||
@@ -31,7 +31,7 @@ type AccountProfile struct {
|
||||
ActivationInterval *ActivationInterval
|
||||
Weight float64
|
||||
Opts map[string]interface{}
|
||||
Balances []*Balance
|
||||
Balances map[string]*Balance
|
||||
ThresholdIDs []string
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func (aP *AccountProfile) Clone() (acnt *AccountProfile) {
|
||||
}
|
||||
}
|
||||
if aP.Balances != nil {
|
||||
acnt.Balances = make([]*Balance, len(aP.Balances))
|
||||
acnt.Balances = make(map[string]*Balance, len(aP.Balances))
|
||||
for i, value := range aP.Balances {
|
||||
acnt.Balances[i] = value.Clone()
|
||||
}
|
||||
@@ -234,7 +234,7 @@ type APIAccountProfile struct {
|
||||
ActivationInterval *ActivationInterval
|
||||
Weight float64
|
||||
Opts map[string]interface{}
|
||||
Balances []*APIBalance
|
||||
Balances map[string]*APIBalance
|
||||
ThresholdIDs []string
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ func (ext *APIAccountProfile) AsAccountProfile() (profile *AccountProfile, err e
|
||||
ThresholdIDs: ext.ThresholdIDs,
|
||||
}
|
||||
if len(ext.Balances) != 0 {
|
||||
profile.Balances = make([]*Balance, len(ext.Balances))
|
||||
profile.Balances = make(map[string]*Balance, len(ext.Balances))
|
||||
for i, bal := range ext.Balances {
|
||||
if profile.Balances[i], err = bal.AsBalance(); err != nil {
|
||||
return
|
||||
|
||||
@@ -71,8 +71,8 @@ func TestCloneAccountProfile(t *testing.T) {
|
||||
Opts: map[string]interface{}{
|
||||
"Destination": 10,
|
||||
},
|
||||
Balances: []*Balance{
|
||||
{
|
||||
Balances: map[string]*Balance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weight: 1.1,
|
||||
|
||||
@@ -1550,7 +1550,7 @@ type TPAccountProfile struct {
|
||||
FilterIDs []string
|
||||
ActivationInterval *TPActivationInterval
|
||||
Weight float64
|
||||
Balances []*TPAccountBalance
|
||||
Balances map[string]*TPAccountBalance
|
||||
ThresholdIDs []string
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user