diff --git a/engine/actions_test.go b/engine/actions_test.go index cbf339451..f8d6656a4 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -2888,3 +2888,204 @@ func TestSetRecurrentAction(t *testing.T) { t.Error(err) } } + +func TestActionSetDDestinations(t *testing.T) { + ub := &Account{ + ID: "ACCID", + ActionTriggers: ActionTriggers{ + &ActionTrigger{ + ID: "acTrigger", + UniqueID: "uuid_acc", + Recurrent: false, + }, + &ActionTrigger{ + ID: "acTrigger1", + UniqueID: "uuid_acc1", + Recurrent: false, + }, + }, + BalanceMap: map[string]Balances{ + utils.MetaMonetary: { + + &Balance{Value: 10, + DestinationIDs: utils.StringMap{ + + "*ddc_dest": true, + "*dest": false, + }}, + }, + utils.MetaVoice: { + &Balance{Value: 10, Weight: 20, DestinationIDs: utils.NewStringMap("NAT")}, + &Balance{Weight: 10, DestinationIDs: utils.NewStringMap("RET")}, + }, + }, + UnitCounters: UnitCounters{ + utils.MetaMonetary: []*UnitCounter{ + { + Counters: CounterFilters{ + &CounterFilter{Value: 1}, + }, + }, + }, + }, + } + a := &Action{ + Id: "CDRLog1", + ActionType: utils.CDRLog, + ExtraParameters: "{\"BalanceID\":\"~*acnt.BalanceID\",\"ActionID\":\"~*act.ActionID\",\"BalanceValue\":\"~*acnt.BalanceValue\"}", + Weight: 50, + } + acs := Actions{ + a, + &Action{ + Id: "CdrDebit", + ActionType: "*debit", + Balance: &BalanceFilter{ + ID: utils.StringPointer(utils.MetaDefault), + Value: &utils.ValueFormula{Static: 9.95}, + Type: utils.StringPointer(utils.MetaMonetary), + Weight: utils.Float64Pointer(0), + }, + Weight: float64(90), + balanceValue: 10, + }, + } + + if err := setddestinations(ub, a, acs, nil, nil); err == nil { + t.Error(err) + } + +} + +func TestActionPublishAccount(t *testing.T) { + ub := &Account{ + ID: "ACCID", + ActionTriggers: ActionTriggers{ + &ActionTrigger{ + ID: "acTrigger", + UniqueID: "uuid_acc", + Recurrent: false, + }, + &ActionTrigger{ + ID: "acTrigger1", + UniqueID: "uuid_acc1", + Recurrent: false, + }, + }, + BalanceMap: map[string]Balances{ + utils.MetaMonetary: { + + &Balance{Value: 10, + DestinationIDs: utils.StringMap{ + + "*ddc_dest": true, + "*dest": false, + }}, + }, + utils.MetaVoice: { + &Balance{Value: 10, Weight: 20, DestinationIDs: utils.NewStringMap("NAT")}, + &Balance{Weight: 10, DestinationIDs: utils.NewStringMap("RET")}, + }, + }, + UnitCounters: UnitCounters{ + utils.MetaMonetary: []*UnitCounter{ + { + Counters: CounterFilters{ + &CounterFilter{Value: 1}, + }, + }, + }, + }, + } + a := &Action{ + Id: "CDRLog1", + ActionType: utils.CDRLog, + ExtraParameters: "{\"BalanceID\":\"~*acnt.BalanceID\",\"ActionID\":\"~*act.ActionID\",\"BalanceValue\":\"~*acnt.BalanceValue\"}", + Weight: 50, + } + acs := Actions{ + a, + &Action{ + Id: "CdrDebit", + ActionType: "*debit", + Balance: &BalanceFilter{ + ID: utils.StringPointer(utils.MetaDefault), + Value: &utils.ValueFormula{Static: 9.95}, + Type: utils.StringPointer(utils.MetaMonetary), + Weight: utils.Float64Pointer(0), + }, + Weight: float64(90), + balanceValue: 10, + }, + } + if err := publishAccount(ub, a, acs, nil, nil); err != nil { + t.Error(err) + } +} + +func TestExportAction(t *testing.T) { + + ub := &Account{ + ID: "ACCID", + ActionTriggers: ActionTriggers{ + &ActionTrigger{ + ID: "acTrigger", + UniqueID: "uuid_acc", + Recurrent: false, + }, + &ActionTrigger{ + ID: "acTrigger1", + UniqueID: "uuid_acc1", + Recurrent: false, + }, + }, + BalanceMap: map[string]Balances{ + utils.MetaMonetary: { + + &Balance{Value: 10, + DestinationIDs: utils.StringMap{ + + "*ddc_dest": true, + "*dest": false, + }}, + }, + utils.MetaVoice: { + &Balance{Value: 10, Weight: 20, DestinationIDs: utils.NewStringMap("NAT")}, + &Balance{Weight: 10, DestinationIDs: utils.NewStringMap("RET")}, + }, + }, + UnitCounters: UnitCounters{ + utils.MetaMonetary: []*UnitCounter{ + { + Counters: CounterFilters{ + &CounterFilter{Value: 1}, + }, + }, + }, + }, + } + a := &Action{ + Id: "CDRLog1", + ActionType: utils.CDRLog, + ExtraParameters: "{\"BalanceID\":\"~*acnt.BalanceID\",\"ActionID\":\"~*act.ActionID\",\"BalanceValue\":\"~*acnt.BalanceValue\"}", + Weight: 50, + } + acs := Actions{ + a, + &Action{ + Id: "CdrDebit", + ActionType: "*debit", + Balance: &BalanceFilter{ + ID: utils.StringPointer(utils.MetaDefault), + Value: &utils.ValueFormula{Static: 9.95}, + Type: utils.StringPointer(utils.MetaMonetary), + Weight: utils.Float64Pointer(0), + }, + Weight: float64(90), + balanceValue: 10, + }, + } + if err := export(ub, a, acs, nil, utils.CGREvent{Tenant: "cgrates.org", ID: "id"}); err == nil { + t.Error(err) + } +} diff --git a/engine/balances_test.go b/engine/balances_test.go index 54ac304fd..8705819c0 100644 --- a/engine/balances_test.go +++ b/engine/balances_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -487,3 +488,119 @@ func TestBalancesHasBalance(t *testing.T) { } } + +func TestBalanceDebitUnits(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + db := NewInternalDB(nil, nil, true, nil) + dm := NewDataManager(db, cfg.CacheCfg(), nil) + cd := &CallDescriptor{ + Category: "postpaid", + ToR: utils.MetaVoice, + Tenant: "foehn", + Subject: "foehn", + Account: "foehn", + Destination: "0034678096720", + TimeStart: time.Date(2015, 4, 24, 7, 59, 4, 0, time.UTC), + TimeEnd: time.Date(2015, 4, 24, 8, 2, 0, 0, time.UTC), + LoopIndex: 0, + DurationIndex: 176 * time.Second, + + FallbackSubject: "", + RatingInfos: RatingInfos{ + &RatingInfo{ + MatchedSubject: "*out:foehn:postpaid:foehn", + MatchedPrefix: "0034678", + MatchedDestId: "SPN_MOB", + ActivationTime: time.Date(2015, 4, 23, 0, 0, 0, 0, time.UTC), + RateIntervals: []*RateInterval{ + { + Timing: &RITiming{ + WeekDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}, + StartTime: "08:00:00", + }, + Rating: &RIRate{ + ConnectFee: 0, + RoundingMethod: "*up", + RoundingDecimals: 6, + Rates: RateGroups{ + &RGRate{Value: 1, RateIncrement: time.Second, RateUnit: time.Second}, + }, + }, + }, + { + Timing: &RITiming{ + WeekDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}, + StartTime: "00:00:00", + }, + Rating: &RIRate{ + ConnectFee: 0, + RoundingMethod: "*up", + RoundingDecimals: 6, + Rates: RateGroups{ + &RGRate{Value: 1, RateIncrement: time.Second, RateUnit: time.Second}, + }, + }, + }, + { + Timing: &RITiming{ + WeekDays: []time.Weekday{time.Saturday, time.Sunday}, + StartTime: "00:00:00", + }, + Rating: &RIRate{ + ConnectFee: 0, + RoundingMethod: "*up", + RoundingDecimals: 6, + Rates: RateGroups{ + &RGRate{Value: 1, RateIncrement: time.Second, RateUnit: time.Second}, + }, + }, + }, + }, + }, + }, + } + ub := &Account{ + ID: "vdf:broker", + BalanceMap: map[string]Balances{ + utils.MetaVoice: { + &Balance{Value: 20 * float64(time.Second), + DestinationIDs: utils.NewStringMap("NAT"), + Weight: 10, RatingSubject: "rif"}, + &Balance{Value: 100 * float64(time.Second), + DestinationIDs: utils.NewStringMap("RET"), Weight: 20}, + }}, + } + + moneyBalances := Balances{{ + Uuid: "uuid", + ID: "id", + Value: 12.22, + ExpirationDate: time.Date(2022, 11, 1, 20, 0, 0, 0, time.UTC), + Blocker: true, + Disabled: true, + precision: 2, + }, + { + Uuid: "uuid2", + ID: "id2", + Value: 133.22, + ExpirationDate: time.Date(2023, 3, 21, 5, 0, 0, 0, time.UTC), + Blocker: true, + Disabled: true, + precision: 2, + }} + b := &Balance{ + Uuid: "uuid", + ID: "id", + Value: 12.22, + ExpirationDate: time.Date(2022, 11, 1, 20, 0, 0, 0, time.UTC), + Blocker: true, + Disabled: true, + precision: 2, + } + fltrs := FilterS{cfg, dm, nil} + + if _, err := b.debitUnits(cd, ub, moneyBalances, true, false, true, &fltrs); err != nil { + t.Error(err) + } +} diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 5e6a610be..2c02133ff 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -1194,6 +1195,10 @@ func TestMaxDebitWithAccountShared(t *testing.T) { if err != nil || other.BalanceMap[utils.MetaMonetary][0].GetValue() != 7.5 { t.Errorf("Error debiting shared balance: %+v", other.BalanceMap[utils.MetaMonetary][0]) } + cd.account.Disabled = true + if _, err := cd.getAccount(); err == nil { + t.Error("expected nil") + } } func TestMaxSessionTimeWithAccountAccount(t *testing.T) { @@ -2545,3 +2550,21 @@ func TestValidateCallData(t *testing.T) { t.Error(err) } } + +func TestCDRefundRounding(t *testing.T) { + cd := &CallDescriptor{ + Category: "call", + Tenant: "cgrates.org", + Subject: "1001", + Account: "1001", + Destination: "1002", + } + cfg := config.NewDefaultCGRConfig() + dataDB := NewInternalDB(nil, nil, true, nil) + dm := NewDataManager(dataDB, cfg.CacheCfg(), nil) + fltrs := NewFilterS(cfg, nil, dm) + + if _, err := cd.RefundRounding(fltrs); err != nil { + t.Error(err) + } +} diff --git a/engine/cdrs_test.go b/engine/cdrs_test.go index 5491e944b..df09f9742 100644 --- a/engine/cdrs_test.go +++ b/engine/cdrs_test.go @@ -20,6 +20,7 @@ package engine import ( "fmt" + "reflect" "testing" "time" @@ -215,3 +216,27 @@ func TestCDRSV1V1ProcessExternalCDRNoTenant(t *testing.T) { t.Error(err) } } + +func TestArgV1ProcessClone(t *testing.T) { + attr := &ArgV1ProcessEvent{ + Flags: []string{"flg,flg2,flg3"}, + CGREvent: utils.CGREvent{ + ID: "TestBiRPCv1AuthorizeEventNoTenant", + Time: utils.TimePointer(time.Date(2016, time.January, 5, 18, 30, 49, 0, time.UTC)), + Event: map[string]interface{}{ + "Account": "1002", + "Category": "call", + "Destination": "1003", + "OriginHost": "local", + "OriginID": "123456", + "ToR": "*voice", + "Usage": "10s", + }, + }, + clnb: true, + } + if val := attr.Clone(); reflect.DeepEqual(attr, val) { + t.Errorf("expected %v,received %v", utils.ToJSON(val), utils.ToJSON(attr)) + } + +} diff --git a/engine/destinations_test.go b/engine/destinations_test.go index c0c58b250..2eb1a9016 100644 --- a/engine/destinations_test.go +++ b/engine/destinations_test.go @@ -169,3 +169,12 @@ func TestDynamicDPFieldAsInterface(t *testing.T) { t.Error(err) } } + +func TestDPNewLibNumber(t *testing.T) { + if _, err := newLibPhoneNumberDP("+3554735474"); err != nil { + t.Errorf("received <%v>", err) + } else if _, err = newLibPhoneNumberDP("some"); err == nil { + t.Error("expected error") + } + +} diff --git a/engine/sharedgroup_test.go b/engine/sharedgroup_test.go index b40fc1b10..c2b015ad6 100644 --- a/engine/sharedgroup_test.go +++ b/engine/sharedgroup_test.go @@ -184,6 +184,24 @@ func TestSharedPopBalanceByStrategyMineHigh(t *testing.T) { } } +func TestSortBalancesByStrategyRandom(t *testing.T) { + + bc := Balances{ + &Balance{Uuid: "uuuu", Value: 2.0, account: &Account{ID: "test"}}, + &Balance{Value: 1.0}, + &Balance{Value: 3.0}, + } + sg := &SharedGroup{AccountParameters: map[string]*SharingParameters{ + "test": {Strategy: "default"}}, + } + + sbc := sg.SortBalancesByStrategy(bc[0], bc) + if len(sbc) != 3 { + t.Error("Error sorting balance chain: ", sbc) + } + +} + /*func TestSharedPopBalanceByStrategyRandomHigh(t *testing.T) { bc := Balances{ &Balance{Uuid: "uuuu", Value: 2.0, account: &Account{Id: "test"}}, diff --git a/engine/storage_test.go b/engine/storage_test.go index 075141f36..1b5a4d9d1 100644 --- a/engine/storage_test.go +++ b/engine/storage_test.go @@ -71,7 +71,6 @@ func TestMsgpackTime(t *testing.T) { t.Errorf("error unmarshalling structure: %#v %#v %v", t1, t2, err) } } - func TestStorageDestinationContainsPrefixShort(t *testing.T) { dest, err := dm.GetDestination("NAT", false, true, utils.NonTransactional) precision := dest.containsPrefix("0723")