From 84e3ac80fe5dc4201db8bfa798666451ac83f449 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 30 Mar 2018 02:52:24 -0400 Subject: [PATCH] Update MaxCost for GetSuppliers --- apier/v1/suppliers_it_test.go | 49 ++++++++++++++++++++++++++++++++++- engine/spls_leastcost.go | 2 +- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index 7edb70fff..b45b27359 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -50,6 +50,7 @@ var sTestsSupplierSV1 = []func(t *testing.T){ testV1SplSFromFolder, testV1SplSGetWeightSuppliers, testV1SplSGetLeastCostSuppliers, + testV1SplSGetLeastCostSuppliersWithMaxCost, testV1SplSGetSupplierWithoutFilter, testV1SplSSetSupplierProfiles, testV1SplSUpdateSupplierProfiles, @@ -165,7 +166,6 @@ func testV1SplSGetWeightSuppliers(t *testing.T) { func testV1SplSGetLeastCostSuppliers(t *testing.T) { ev := &engine.ArgsGetSuppliers{ - //MaxCost: 0.020, CGREvent: utils.CGREvent{ Tenant: "cgrates.org", ID: "testV1SplSGetLeastCostSuppliers", @@ -218,6 +218,53 @@ func testV1SplSGetLeastCostSuppliers(t *testing.T) { } } +func testV1SplSGetLeastCostSuppliersWithMaxCost(t *testing.T) { + ev := &engine.ArgsGetSuppliers{ + MaxCost: 0.30, + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testV1SplSGetLeastCostSuppliers", + Event: map[string]interface{}{ + utils.Account: "1001", + utils.Subject: "1001", + utils.Destination: "1002", + utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC), + utils.Usage: "1m20s", + }, + }, + } + eSpls := engine.SortedSuppliers{ + ProfileID: "SPL_LEASTCOST_1", + Sorting: utils.MetaLeastCost, + SortedSuppliers: []*engine.SortedSupplier{ + &engine.SortedSupplier{ + SupplierID: "supplier3", + SortingData: map[string]interface{}{ + utils.Cost: 0.02, + utils.RatingPlanID: "RP_SPECIAL_1002", + utils.Weight: 15.0, + }, + }, + &engine.SortedSupplier{ + SupplierID: "supplier1", + SortingData: map[string]interface{}{ + utils.Cost: 0.02, + utils.RatingPlanID: "RP_SPECIAL_1002", + utils.Weight: 10.0, + }, + }, + }, + } + var suplsReply engine.SortedSuppliers + if err := splSv1Rpc.Call(utils.SupplierSv1GetSuppliers, + ev, &suplsReply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eSpls, suplsReply) { + t.Errorf("Expecting: %s, received: %s", + utils.ToJSON(eSpls), utils.ToJSON(suplsReply)) + } +} + func testV1SplSGetSupplierWithoutFilter(t *testing.T) { ev := &engine.ArgsGetSuppliers{ CGREvent: utils.CGREvent{ diff --git a/engine/spls_leastcost.go b/engine/spls_leastcost.go index caad60a84..d8701680d 100644 --- a/engine/spls_leastcost.go +++ b/engine/spls_leastcost.go @@ -56,7 +56,7 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string, return nil, err } utils.Logger.Debug(fmt.Sprintf("maxCost : %+v and cost costData[utils.Cost] %+v", float64(*lcs.spS.maxCost), cost)) - if cost > float64(*lcs.spS.maxCost) { + if cost > *lcs.spS.maxCost && *lcs.spS.maxCost != 0 { continue } srtData := map[string]interface{}{