diff --git a/apier/v1/cache_replication_it_test.go b/apier/v1/cache_replication_it_test.go index 05291c886..a66873b47 100644 --- a/apier/v1/cache_replication_it_test.go +++ b/apier/v1/cache_replication_it_test.go @@ -211,10 +211,8 @@ func testCacheSReplicateProcessRateProfile(t *testing.T) { }, } exp := &engine.RateProfileCost{ - ID: "RT_SPECIAL_1002", - Cost: 0.01, - RoundingDecimals: 4, - RoundingMethod: utils.MetaUp, + ID: "RT_SPECIAL_1002", + Cost: 0.01, RateSIntervals: []*engine.RateSInterval{{ UsageStart: 0, diff --git a/apier/v1/tprateprofiles_it_test.go b/apier/v1/tprateprofiles_it_test.go index b3b2c80ff..f050add43 100644 --- a/apier/v1/tprateprofiles_it_test.go +++ b/apier/v1/tprateprofiles_it_test.go @@ -121,13 +121,11 @@ func testTPRatePrfGetTPRatePrfBeforeSet(t *testing.T) { func testTPRatePrfSetTPRatePrf(t *testing.T) { tpRatePrf = &utils.TPRateProfile{ - TPid: "TP1", - Tenant: "cgrates.org", - ID: "RT_SPECIAL_1002", - Weight: 10, - RoundingDecimals: 4, - RoundingMethod: "*up", - FilterIDs: make([]string, 0), + TPid: "TP1", + Tenant: "cgrates.org", + ID: "RT_SPECIAL_1002", + Weight: 10, + FilterIDs: make([]string, 0), Rates: map[string]*utils.TPRate{ "RT_ALWAYS": { ID: "RT_ALWAYS", diff --git a/dispatchers/rates_it_test.go b/dispatchers/rates_it_test.go index f3169e5f5..e8aaff355 100644 --- a/dispatchers/rates_it_test.go +++ b/dispatchers/rates_it_test.go @@ -85,26 +85,22 @@ func testDspRPrfPing(t *testing.T) { } func testDspRPrfCostForEvent(t *testing.T) { - minDecimal, err := utils.NewDecimalFromUnit("1m") - if err != nil { - t.Error(err) - } - rPrf := &engine.RateProfile{ + rPrf := &engine.APIRateProfile{ ID: "DefaultRate", Tenant: "cgrates.org", FilterIDs: []string{"*string:~*req.Subject:1001"}, Weight: 10, - Rates: map[string]*engine.Rate{ + Rates: map[string]*engine.APIRate{ "RT_WEEK": { ID: "RT_WEEK", Weight: 0, ActivationTimes: "* * * * *", - IntervalRates: []*engine.IntervalRate{ + IntervalRates: []*engine.APIIntervalRate{ { - IntervalStart: 0, - RecurrentFee: utils.NewDecimal(12, 2), - Unit: minDecimal, - Increment: minDecimal, + IntervalStart: "0", + RecurrentFee: utils.Float64Pointer(0.12), + Unit: utils.Float64Pointer(float64(time.Minute)), + Increment: utils.Float64Pointer(float64(time.Minute)), }, }, }, @@ -123,6 +119,10 @@ func testDspRPrfCostForEvent(t *testing.T) { }, &rply); err != nil { t.Error(err) } + rtWeek, err := rPrf.Rates["RT_WEEK"].AsRate() + if err != nil { + t.Fatal(err) + } exp := &engine.RateProfileCost{ ID: "DefaultRate", Cost: 0.12, @@ -131,7 +131,7 @@ func testDspRPrfCostForEvent(t *testing.T) { Increments: []*engine.RateSIncrement{{ UsageStart: 0, Usage: time.Minute, - Rate: rPrf.Rates["RT_WEEK"], + Rate: rtWeek, IntervalRateIndex: 0, CompressFactor: 1, }}, @@ -154,34 +154,26 @@ func testDspRPrfCostForEvent(t *testing.T) { }}}, &rpCost); err != nil { t.Error(err) } else if !reflect.DeepEqual(rpCost, exp) { - t.Errorf("Expected %+v, received %+v", exp, rpCost) + t.Errorf("Expected %+v, received %+v", utils.ToJSON(exp), utils.ToJSON(rpCost)) } } func testDspRPrfCostForEventWithoutFilters(t *testing.T) { - minDecimal, err := utils.NewDecimalFromUnit("1m") - if err != nil { - t.Error(err) - } - secDecimal, err := utils.NewDecimalFromUnit("1s") - if err != nil { - t.Error(err) - } - rPrf := &engine.RateProfile{ + rPrf := &engine.APIRateProfile{ ID: "ID_RP", Tenant: "cgrates.org", Weight: 10, - Rates: map[string]*engine.Rate{ + Rates: map[string]*engine.APIRate{ "RT_WEEK": { ID: "RT_WEEK", Weight: 0, ActivationTimes: "* * * * *", - IntervalRates: []*engine.IntervalRate{ + IntervalRates: []*engine.APIIntervalRate{ { - IntervalStart: 0, - RecurrentFee: utils.NewDecimal(25, 2), - Unit: minDecimal, - Increment: secDecimal, + IntervalStart: "0", + RecurrentFee: utils.Float64Pointer(0.25), + Unit: utils.Float64Pointer(float64(time.Minute)), + Increment: utils.Float64Pointer(float64(time.Second)), }, }, }, @@ -200,6 +192,10 @@ func testDspRPrfCostForEventWithoutFilters(t *testing.T) { }, &rply); err != nil { t.Error(err) } + rtWeek, err := rPrf.Rates["RT_WEEK"].AsRate() + if err != nil { + t.Fatal(err) + } exp := &engine.RateProfileCost{ ID: "ID_RP", Cost: 0.25, @@ -208,7 +204,7 @@ func testDspRPrfCostForEventWithoutFilters(t *testing.T) { Increments: []*engine.RateSIncrement{{ UsageStart: 0, Usage: time.Minute, - Rate: rPrf.Rates["RT_WEEK"], + Rate: rtWeek, IntervalRateIndex: 0, CompressFactor: 60, }}, diff --git a/dispatchers/replicator_it_test.go b/dispatchers/replicator_it_test.go index b7bb7e167..31630fbf0 100644 --- a/dispatchers/replicator_it_test.go +++ b/dispatchers/replicator_it_test.go @@ -1473,13 +1473,11 @@ func testDspRplRateProfile(t *testing.T) { var replyStr string rPrf := &engine.RateProfileWithOpts{ RateProfile: &engine.RateProfile{ - Tenant: "cgrates.org", - ID: "RP1", - FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"}, - Weight: 0, - RoundingMethod: "*up", - RoundingDecimals: 4, - MaxCostStrategy: "*free", + Tenant: "cgrates.org", + ID: "RP1", + FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"}, + Weight: 0, + MaxCostStrategy: "*free", Rates: map[string]*engine.Rate{ "FIRST_GI": { ID: "FIRST_GI", diff --git a/engine/rateprofile.go b/engine/rateprofile.go index f57d68c12..1b3e475ce 100644 --- a/engine/rateprofile.go +++ b/engine/rateprofile.go @@ -144,27 +144,18 @@ type RateSIncrement struct { // RateProfileCost is the cost returned by RateS at cost queries type RateProfileCost struct { - ID string // RateProfileID - Cost float64 - RoundingDecimals int - RoundingMethod string - MinCost float64 - MaxCost float64 - MaxCostStrategy string - RateSIntervals []*RateSInterval - Altered []string + ID string // RateProfileID + Cost float64 + MinCost float64 + MaxCost float64 + MaxCostStrategy string + RateSIntervals []*RateSInterval + Altered []string } // CorrectCost should be called in final phase of cost calculation // in order to apply further correction like Min/MaxCost or rounding func (rPc *RateProfileCost) CorrectCost(rndDec *int, rndMtd string) { - if rndDec != nil { - rPc.RoundingDecimals = *rndDec - if rndMtd != utils.EmptyString { - rPc.RoundingMethod = rndMtd - } - - } if rPc.MinCost != 0 && rPc.Cost < rPc.MinCost { rPc.Cost = rPc.MinCost rPc.Altered = append(rPc.Altered, utils.MinCost) @@ -173,8 +164,8 @@ func (rPc *RateProfileCost) CorrectCost(rndDec *int, rndMtd string) { rPc.Cost = rPc.MaxCost rPc.Altered = append(rPc.Altered, utils.MaxCost) } - if rPc.RoundingDecimals != 0 { - rPc.Cost = utils.Round(rPc.Cost, rPc.RoundingDecimals, rPc.RoundingMethod) + if rndDec != nil { + rPc.Cost = utils.Round(rPc.Cost, *rndDec, rndMtd) rPc.Altered = append(rPc.Altered, utils.RoundingDecimals) } } diff --git a/migrator/rateprofiles_it_test.go b/migrator/rateprofiles_it_test.go index 73a9161fe..faa46d40f 100644 --- a/migrator/rateprofiles_it_test.go +++ b/migrator/rateprofiles_it_test.go @@ -186,15 +186,13 @@ func testRatePrfITMigrateAndMove(t *testing.T) { t.Error(err) } rPrf := &engine.RateProfile{ - Tenant: "cgrates.org", - ID: "RP1", - FilterIDs: []string{"*string:~*req.Subject:1001"}, - Weight: 0, - RoundingMethod: "*up", - RoundingDecimals: 4, - MinCost: utils.NewDecimal(1, 1), - MaxCost: utils.NewDecimal(6, 1), - MaxCostStrategy: "*free", + Tenant: "cgrates.org", + ID: "RP1", + FilterIDs: []string{"*string:~*req.Subject:1001"}, + Weight: 0, + MinCost: utils.NewDecimal(1, 1), + MaxCost: utils.NewDecimal(6, 1), + MaxCostStrategy: "*free", Rates: map[string]*engine.Rate{ "FIRST_GI": { ID: "FIRST_GI", diff --git a/migrator/tp_rate_profiles_it_test.go b/migrator/tp_rate_profiles_it_test.go index 953699c84..4cf9853e4 100644 --- a/migrator/tp_rate_profiles_it_test.go +++ b/migrator/tp_rate_profiles_it_test.go @@ -104,16 +104,14 @@ func testTPRateProfileFlush(t *testing.T) { func testTPRateProfilePopulate(t *testing.T) { tpRateProfiles = []*utils.TPRateProfile{ { - TPid: "id_RP1", - Tenant: "cgrates.org", - ID: "RP1", - FilterIDs: []string{"*string:~*req.Subject:1001"}, - Weight: 0, - RoundingMethod: "*up", - RoundingDecimals: 4, - MinCost: 0.1, - MaxCost: 0.6, - MaxCostStrategy: "*free", + TPid: "id_RP1", + Tenant: "cgrates.org", + ID: "RP1", + FilterIDs: []string{"*string:~*req.Subject:1001"}, + Weight: 0, + MinCost: 0.1, + MaxCost: 0.6, + MaxCostStrategy: "*free", Rates: map[string]*utils.TPRate{ "FIRST_GI": { ID: "FIRST_GI",