diff --git a/engine/libeventcost_test.go b/engine/libeventcost_test.go index 244579571..5fcad900e 100755 --- a/engine/libeventcost_test.go +++ b/engine/libeventcost_test.go @@ -629,23 +629,25 @@ func TestRatingFiltersGetIDWithSet(t *testing.T) { }, } - id1 := rf1.GetIDWithSet(RatingMatchedFilters{ + if id1 := rf1.GetIDWithSet(RatingMatchedFilters{ "AccountID": "1001", "Units": 2.34, "ExtraChargeID": "Extra1", - }) - if id1 != "Key1" { + }); id1 != "Key1" { t.Errorf("Expecting: Key1, received: %+v", id1) } - id2 := rf1.GetIDWithSet(RatingMatchedFilters{ + if id2 := rf1.GetIDWithSet(RatingMatchedFilters{ "AccountID": "1004", "Units": 2.34, "ExtraChargeID": "Extra3", - }) - if id2 == "" { + }); id2 == "" { t.Errorf("Expecting id , received: %+v", id2) } + + if id3 := rf1.GetIDWithSet(nil); id3 != "" { + t.Errorf("Expecting , received: %+v", id3) + } } func TestRatingFiltersClone(t *testing.T) { @@ -670,3 +672,350 @@ func TestRatingFiltersClone(t *testing.T) { t.Errorf("Expecting 1001 , received: %+v", rf2) } } + +//Start tests for Rating +func TestRatingGetIDWithSet(t *testing.T) { + r1 := Rating{ + "Key1": &RatingUnit{ + ConnectFee: 1.23, + RoundingMethod: "Meth1", + RoundingDecimals: 4, + MaxCost: 3.45, + MaxCostStrategy: "MaxMeth", + TimingID: "TimingID1", + RatesID: "RatesID1", + RatingFiltersID: "RatingFltrID1", + }, + "Key2": &RatingUnit{ + ConnectFee: 0.2, + RoundingMethod: "Meth1", + RoundingDecimals: 4, + MaxCost: 2.12, + MaxCostStrategy: "MaxMeth", + TimingID: "TimingID1", + RatesID: "RatesID1", + RatingFiltersID: "RatingFltrID1", + }, + } + + if id1 := r1.GetIDWithSet(&RatingUnit{ + ConnectFee: 1.23, + RoundingMethod: "Meth1", + RoundingDecimals: 4, + MaxCost: 3.45, + MaxCostStrategy: "MaxMeth", + TimingID: "TimingID1", + RatesID: "RatesID1", + RatingFiltersID: "RatingFltrID1", + }); id1 != "Key1" { + t.Errorf("Expecting: Key1, received: %+v", id1) + } + + if id2 := r1.GetIDWithSet(&RatingUnit{ + ConnectFee: 0.23, + RoundingMethod: "Meth1", + RoundingDecimals: 4, + MaxCost: 3.45, + MaxCostStrategy: "MaxMeth", + TimingID: "TimingID1", + RatesID: "RatesID1", + RatingFiltersID: "RatingFltrID1", + }); id2 == "" { + t.Errorf("Expecting id , received: %+v", id2) + } + + if id3 := r1.GetIDWithSet(nil); id3 != "" { + t.Errorf("Expecting , received: %+v", id3) + } +} + +func TestRatingClone(t *testing.T) { + rf1 := Rating{ + "Key1": &RatingUnit{ + ConnectFee: 1.23, + RoundingMethod: "Meth1", + RoundingDecimals: 4, + MaxCost: 3.45, + MaxCostStrategy: "MaxMeth", + TimingID: "TimingID1", + RatesID: "RatesID1", + RatingFiltersID: "RatingFltrID1", + }, + "Key2": &RatingUnit{ + ConnectFee: 0.2, + RoundingMethod: "Meth1", + RoundingDecimals: 4, + MaxCost: 2.12, + MaxCostStrategy: "MaxMeth", + TimingID: "TimingID1", + RatesID: "RatesID1", + RatingFiltersID: "RatingFltrID1", + }, + } + rf2 := rf1.Clone() + if !reflect.DeepEqual(rf1, rf2) { + t.Errorf("Expecting: %+v, received: %+v", rf1, rf2) + } + rf1["Key1"].RatesID = "RatesID2" + if rf2["Key1"].RatesID != "RatesID1" { + t.Errorf("Expecting RatesID1 , received: %+v", rf2) + } +} + +//Start tests for ChargedRates +func TestChargedRatesGetIDWithSet(t *testing.T) { + cr1 := ChargedRates{ + "Key1": RateGroups{ + &Rate{ + GroupIntervalStart: time.Hour, + Value: 0.17, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + &Rate{ + GroupIntervalStart: time.Hour, + Value: 0.17, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + }, + "Key2": RateGroups{ + &Rate{ + GroupIntervalStart: time.Hour, + Value: 1.12, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + &Rate{ + GroupIntervalStart: 0, + Value: 2, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + }, + } + + // in rate interval at line 292 + // RateGroups verify only the firs Rate with the others + if id1 := cr1.GetIDWithSet(RateGroups{ + &Rate{ + GroupIntervalStart: time.Hour, + Value: 0.17, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + &Rate{ + GroupIntervalStart: time.Hour, + Value: 0.17, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + }); id1 != "Key1" { + t.Errorf("Expecting: Key1, received: %+v", id1) + } + + id2 := cr1.GetIDWithSet(RateGroups{ + &Rate{ + GroupIntervalStart: time.Hour, + Value: 1, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + &Rate{ + GroupIntervalStart: 0, + Value: 2, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + }) + if id2 == "" { + t.Errorf("Expecting id , received: %+v", id2) + } + + if id3 := cr1.GetIDWithSet(nil); id3 != "" { + t.Errorf("Expecting , received: %+v", id3) + } +} + +func TestChargedRatesClone(t *testing.T) { + cr1 := ChargedRates{ + "Key1": RateGroups{ + &Rate{ + GroupIntervalStart: time.Hour, + Value: 0.17, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + &Rate{ + GroupIntervalStart: 0, + Value: 0.7, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + }, + "Key2": RateGroups{ + &Rate{ + GroupIntervalStart: time.Hour, + Value: 1.12, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + &Rate{ + GroupIntervalStart: 0, + Value: 2, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + }, + } + cr2 := cr1.Clone() + if !reflect.DeepEqual(cr1, cr2) { + t.Errorf("Expecting: %+v, received: %+v", cr1, cr2) + } + cr1["Key1"][0].Value = 12.2 + if cr2["Key1"][0].Value != 0.17 { + t.Errorf("Expecting 0.17 , received: %+v", cr2) + } +} + +//Start tests for ChargedTimings +func TestChargedTimingsGetIDWithSet(t *testing.T) { + ct1 := ChargedTimings{ + "Key1": &ChargedTiming{ + Years: utils.Years{2, 2}, + Months: utils.Months{2, 3}, + MonthDays: utils.MonthDays{1, 2, 3, 5}, + WeekDays: utils.WeekDays{2, 3}, + StartTime: "Time", + }, + "Key2": &ChargedTiming{ + Years: utils.Years{1, 2}, + Months: utils.Months{2, 3}, + MonthDays: utils.MonthDays{4, 5}, + WeekDays: utils.WeekDays{2, 3}, + StartTime: "Time", + }, + } + + if id1 := ct1.GetIDWithSet(&ChargedTiming{ + Years: utils.Years{2, 2}, + Months: utils.Months{2, 3}, + MonthDays: utils.MonthDays{1, 2, 3, 5}, + WeekDays: utils.WeekDays{2, 3}, + StartTime: "Time", + }); id1 != "Key1" { + t.Errorf("Expecting: Key1, received: %+v", id1) + } + + if id2 := ct1.GetIDWithSet(&ChargedTiming{ + Years: utils.Years{1, 2, 3}, + Months: utils.Months{2, 3}, + MonthDays: utils.MonthDays{1, 2, 3, 5}, + WeekDays: utils.WeekDays{2, 4, 3}, + StartTime: "Time", + }); id2 == "" { + t.Errorf("Expecting id , received: %+v", id2) + } + + if id3 := ct1.GetIDWithSet(nil); id3 != "" { + t.Errorf("Expecting , received: %+v", id3) + } +} + +func TestChargedTimingsClone(t *testing.T) { + ct1 := ChargedTimings{ + "Key1": &ChargedTiming{ + Years: utils.Years{2, 2}, + Months: utils.Months{2, 3}, + MonthDays: utils.MonthDays{1, 2, 3, 5}, + WeekDays: utils.WeekDays{2, 3}, + StartTime: "Time", + }, + "Key2": &ChargedTiming{ + Years: utils.Years{1, 2}, + Months: utils.Months{2, 3}, + MonthDays: utils.MonthDays{4, 5}, + WeekDays: utils.WeekDays{2, 3}, + StartTime: "Time", + }, + } + ct2 := ct1.Clone() + if !reflect.DeepEqual(ct1, ct2) { + t.Errorf("Expecting: %+v, received: %+v", ct1, ct2) + } + ct1["Key1"].StartTime = "Time2" + if ct2["Key1"].StartTime != "Time" { + t.Errorf("Expecting Time , received: %+v", ct2) + } +} + +//Start tests for Accounting +func TestAccountingGetIDWithSet(t *testing.T) { + a1 := Accounting{ + "Key1": &BalanceCharge{ + AccountID: "1001", + BalanceUUID: "ASD_FGH", + RatingID: "Rating1001", + Units: 2.34, + ExtraChargeID: "Extra1", + }, + "Key2": &BalanceCharge{ + AccountID: "1002", + BalanceUUID: "ASD_FGH", + RatingID: "Rating1001", + Units: 1.23, + ExtraChargeID: "Extra1", + }, + } + + if id1 := a1.GetIDWithSet(&BalanceCharge{ + AccountID: "1001", + BalanceUUID: "ASD_FGH", + RatingID: "Rating1001", + Units: 2.34, + ExtraChargeID: "Extra1", + }); id1 != "Key1" { + t.Errorf("Expecting: Key1, received: %+v", id1) + } + + if id2 := a1.GetIDWithSet(&BalanceCharge{ + AccountID: "1002", + BalanceUUID: "ASD_FGH", + RatingID: "Rating1001", + Units: 2.34, + ExtraChargeID: "Extra1", + }); id2 == "" { + t.Errorf("Expecting id , received: %+v", id2) + } + + if id3 := a1.GetIDWithSet(nil); id3 != "" { + t.Errorf("Expecting , received: %+v", id3) + } +} + +func TestAccountingClone(t *testing.T) { + a1 := Accounting{ + "Key1": &BalanceCharge{ + AccountID: "1001", + BalanceUUID: "ASD_FGH", + RatingID: "Rating1001", + Units: 2.34, + ExtraChargeID: "Extra1", + }, + "Key2": &BalanceCharge{ + AccountID: "1002", + BalanceUUID: "ASD_FGH", + RatingID: "Rating1001", + Units: 1.23, + ExtraChargeID: "Extra1", + }, + } + a2 := a1.Clone() + if !reflect.DeepEqual(a1, a2) { + t.Errorf("Expecting: %+v, received: %+v", a1, a2) + } + a1["Key1"].AccountID = "1004" + if a2["Key1"].AccountID != "1001" { + t.Errorf("Expecting 1001 , received: %+v", a2) + } +}