diff --git a/engine/account_test.go b/engine/account_test.go index 3b4e7d28f..d869397ba 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -2932,3 +2933,36 @@ func TestAccountGetCreditForPrefix(t *testing.T) { t.Errorf("received %+v", utils.ToJSON(balances)) } } + +func TestAcountSetBalanceAction(t *testing.T) { + + cfg := config.NewDefaultCGRConfig() + acc := &Account{ + ID: "rif", + AllowNegative: true, + BalanceMap: map[string]Balances{ + utils.MetaSMS: {&Balance{Value: 14}}, + utils.MetaData: {&Balance{Value: 1204}}, + utils.MetaVoice: { + &Balance{Weight: 20, + DestinationIDs: utils.StringMap{"NAT": true}}, + &Balance{Weight: 10, + DestinationIDs: utils.StringMap{"RET": true}}}}, + } + fltrs := NewFilterS(cfg, nil, nil) + + a := &Action{ + Balance: &BalanceFilter{ + Uuid: utils.StringPointer(utils.EmptyString), + ID: utils.StringPointer(utils.MetaDefault), + Type: utils.StringPointer("b_type"), + Value: &utils.ValueFormula{ + + Method: "value_method", + }, + }, + } + if err := acc.setBalanceAction(a, fltrs); err != nil { + t.Error(err) + } +} diff --git a/engine/actions_test.go b/engine/actions_test.go index 3354e1e00..8cdbe4700 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -3346,9 +3346,11 @@ func TestResetAccountCDRSuccesful(t *testing.T) { /* func TestRemoveSessionCost(t *testing.T) { + Cache.Clear(nil) cfg := config.NewDefaultCGRConfig() db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) + fl := &Filter{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "BalanceID;", @@ -3374,9 +3376,11 @@ func TestRemoveSessionCost(t *testing.T) { }, } dm.SetFilter(fl, true) + Cache = NewCacheS(cfg, dm, nil) + SetDataStorage(dm) action := &Action{ - ExtraParameters: "{BalanceID;~*acnt.BalanceID;ActionID;~*act.ActionID;BalanceValue;~*acnt.BalanceValue}", + ExtraParameters: "BalanceID;~*acnt.BalanceID;ActionID;~*act.ActionID;BalanceValue;~*acnt.BalanceValue", } if err := removeSessionCosts(nil, action, nil, nil, nil); err != nil { t.Error(err) diff --git a/engine/balances_test.go b/engine/balances_test.go index c0814e1dd..3ddafa5b6 100644 --- a/engine/balances_test.go +++ b/engine/balances_test.go @@ -640,7 +640,64 @@ func TestBalanceDebitUnits(t *testing.T) { } } func TestBalanceDebitMoney(t *testing.T) { - cd := &CallDescriptor{} + cd := &CallDescriptor{ + testCallcost: &CallCost{Category: "postpaid", + Tenant: "foehn", + Subject: "foehn", Account: "foehn", + Destination: "0034678096720", ToR: "*voice", + Cost: 0, + Timespans: TimeSpans{ + {TimeStart: time.Date(2015, 4, 24, 7, 59, 4, 0, time.UTC), + TimeEnd: time.Date(2015, 4, 24, 8, 2, 0, 0, time.UTC), + Cost: 0, + RateInterval: &RateInterval{ + Rating: &RIRate{ + ConnectFee: 5, + RoundingDecimals: 3, + MaxCost: 0, + Rates: RateGroups{ + { + GroupIntervalStart: 0, + Value: 0, + RateIncrement: 34, + RateUnit: 34}, + }}, + Weight: 0}, + DurationIndex: 26, + MatchedSubject: "uuid3", + MatchedPrefix: "00346786720", + MatchedDestId: "*any", + RatingPlanId: "*none", + CompressFactor: 0}, + + {TimeStart: time.Date(2015, 4, 24, 7, 59, 4, 0, time.UTC), + TimeEnd: time.Date(2015, 4, 24, 8, 2, 0, 0, time.UTC), + Cost: 0, + RateInterval: &RateInterval{ + Rating: &RIRate{ + ConnectFee: 0, + RoundingDecimals: 0, + MaxCost: 0, + Rates: RateGroups{ + { + GroupIntervalStart: 0, + Value: 0, + RateIncrement: 34, + RateUnit: 34}, + }}, + Weight: 0}, + DurationIndex: 26, + MatchedSubject: "uuid", + MatchedPrefix: "0034678096720", + MatchedDestId: "*any", + RatingPlanId: "*none", + CompressFactor: 5}, + }, + RatedUsage: 0, + deductConnectFee: true, + }, + } + ub := &Account{} moneyBalances := Balances{} @@ -649,7 +706,7 @@ func TestBalanceDebitMoney(t *testing.T) { Timings: []*RITiming{}, } if val, err := b.debitMoney(cd, ub, moneyBalances, true, true, true, nil); err != nil { - t.Errorf("expected nil,received %+v", val) + t.Errorf("expected nil,received %+v", utils.ToJSON(val)) } } diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 7a681f484..a719b9251 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -2591,3 +2591,24 @@ func TestCDRefundRounding(t *testing.T) { t.Errorf("received %v", val) } } + +func TestCdAddRatingInfos(t *testing.T) { + + cd := &CallDescriptor{ + TimeStart: time.Date(2022, 12, 5, 0, 0, 0, 0, time.UTC), + RatingInfos: RatingInfos{ + &RatingInfo{ + ActivationTime: time.Date(2022, 12, 4, 0, 0, 0, 0, time.UTC), + }, + }, + } + riS := RatingInfos{ + { + ActivationTime: time.Date(2022, 12, 4, 0, 0, 0, 0, time.UTC), + }, + } + if has := cd.addRatingInfos(riS); !has { + t.Error("expected true,received false") + } + +} diff --git a/engine/cdrs_test.go b/engine/cdrs_test.go index 16eb84265..50b6a5a23 100644 --- a/engine/cdrs_test.go +++ b/engine/cdrs_test.go @@ -25,6 +25,7 @@ import ( "time" "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" ) @@ -1593,12 +1594,7 @@ func TestCdrServerStoreSMCost(t *testing.T) { }, }) dm := NewDataManager(db, cfg.CacheCfg(), nil) - cdrS := &CDRServer{ - cgrCfg: cfg, - cdrDb: db, - dm: dm, - connMgr: connMgr, - } + smCost := &SMCost{ CGRID: "cgrid", RunID: "runid", @@ -1619,6 +1615,14 @@ func TestCdrServerStoreSMCost(t *testing.T) { Rates: ChargedRates{}, }, } + guardian := guardian.GuardianLocker{} + cdrS := &CDRServer{ + cgrCfg: cfg, + cdrDb: db, + dm: dm, + connMgr: connMgr, + guard: &guardian, + } if err := cdrS.cdrDb.SetSMCost(smCost); err != nil { t.Error(err) } diff --git a/engine/destinations_test.go b/engine/destinations_test.go index fbaa327d4..9024f322d 100644 --- a/engine/destinations_test.go +++ b/engine/destinations_test.go @@ -192,3 +192,54 @@ func TestDPNewLibNumber(t *testing.T) { } } + +/* +func TestDMSetDestination(t *testing.T) { + Cache.Clear(nil) + cfg := config.NewDefaultCGRConfig() + cfg.DataDbCfg().Items = map[string]*config.ItemOpt{ + utils.MetaDestinations: &config.ItemOpt{ + Replicate: true, + }, + } + cfg.DataDbCfg().RplConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicationConnsCfg)} + cfg.DataDbCfg().RplFiltered = true + cfg.DataDbCfg().RplCache = "cache" + + db := NewInternalDB(nil, nil, true, map[string]*config.ItemOpt{ + utils.CacheDestinations: { + Limit: 2, + TTL: 2 * time.Minute, + StaticTTL: true, + Remote: true, + Replicate: true, + RouteID: "route", + APIKey: "api", + }, + }) + clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn <- &ccMock{ + calls: map[string]func(args interface{}, reply interface{}) error{ + utils.ReplicatorSv1SetDestination: func(args, reply interface{}) error { + *reply.(*string) = "reply" + return nil + }, + }, + } + connMngr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicationConnsCfg): clientConn, + }) + + dest := &Destination{ + Id: "dest21", + Prefixes: []string{}, + } + dm := NewDataManager(db, cfg.CacheCfg(), connMngr) + config.SetCgrConfig(cfg) + Cache = NewCacheS(cfg, dm, nil) + if err := dm.SetDestination(dest, utils.NonTransactional); err != nil { + t.Error(err) + } + +} +*/ diff --git a/engine/dynamicdp_test.go b/engine/dynamicdp_test.go index ab7b00e38..8d4dcede1 100644 --- a/engine/dynamicdp_test.go +++ b/engine/dynamicdp_test.go @@ -23,6 +23,7 @@ import ( "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" + "github.com/nyaruka/phonenumbers" ) func TestDynamicDpFieldAsInterface(t *testing.T) { @@ -56,3 +57,40 @@ func TestDynamicDpFieldAsInterface(t *testing.T) { } } + +func TestDpLibPhoneNumber(t *testing.T) { + + libphonenumber := &libphonenumberDP{ + pNumber: &phonenumbers.PhoneNumber{ + CountryCode: func(i int32) *int32 { + + return &i + }(33), + NationalNumber: func(i uint64) *uint64 { + + return &i + }(121411111), + }, + cache: utils.MapStorage{}, + } + if val, err := libphonenumber.fieldAsInterface([]string{"CountryCode"}); err != nil { + t.Error(err) + } else if val != *libphonenumber.pNumber.CountryCode { + t.Errorf("expected %v,received %v", libphonenumber.pNumber.CountryCode, val) + } + + if val, err := libphonenumber.fieldAsInterface([]string{"NationalNumber"}); err != nil { + t.Error(err) + } else if val != *libphonenumber.pNumber.NationalNumber { + t.Errorf("expected %v,received %v", libphonenumber.pNumber.CountryCode, val) + } + + if val, err := libphonenumber.fieldAsInterface([]string{"Region"}); err != nil { + t.Error(err) + } else if val != "FR" { + t.Errorf("expected %v,received %v", "FR", val) + } + if _, err := libphonenumber.fieldAsInterface([]string{"NumberType"}); err != nil { + t.Error(err) + } +} diff --git a/engine/tpreader_test.go b/engine/tpreader_test.go index 76f646e41..7b89ecc34 100644 --- a/engine/tpreader_test.go +++ b/engine/tpreader_test.go @@ -1141,3 +1141,16 @@ func TestTpReaderReloadScheduler(t *testing.T) { } } + +func TestTpReaderIsValid(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) + tpr, err := NewTpReader(nil, db, "", "local", nil, nil, false) + if err != nil { + t.Error(err) + } + if valid := tpr.IsValid(); !valid { + t.Error("expected true,received false") + } + +}