From ffd39481adea5411bd242c454f82c1bb7d5459ae Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 12 Jul 2019 13:46:17 +0300 Subject: [PATCH] Add test for special case in case of suppliers --- apier/v1/suppliers_it_test.go | 92 ++++++++++++++++++++ data/tariffplans/testit/DestinationRates.csv | 5 +- data/tariffplans/testit/Destinations.csv | 3 +- data/tariffplans/testit/RatingPlans.csv | 4 +- 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index c4d708c13..073fd2968 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -67,6 +67,10 @@ var sTestsSupplierSV1 = []func(t *testing.T){ testV1SplSUpdateSupplierProfiles, testV1SplSRemSupplierProfiles, testV1SplSGetSupplierForEvent, + //reset the database and load the TP again + testV1SplSInitDataDb, + testV1SplSFromFolder, + testV1SplsOneSupplierWithoutDestination, testV1SplSupplierPing, testV1SplSStopEngine, } @@ -950,6 +954,94 @@ func testV1SplSGetSupplierForEvent(t *testing.T) { } } +// Scenario: We create two rating plans RP_MOBILE and RP_LOCAL +// RP_LOCAL contains destination for both mobile and local +// and RP_MOBILE contains destinations only for mobile +// Create a SupplierProfile with *least_cost strategy with 2 suppliers +// supplier1 have attached RP_LOCAL and supplier2 have attach RP_MOBILE +func testV1SplsOneSupplierWithoutDestination(t *testing.T) { + var reply *engine.SupplierProfile + if err := splSv1Rpc.Call("ApierV1.GetSupplierProfile", + &utils.TenantID{Tenant: "cgrates.org", ID: "SPL_DESTINATION"}, &reply); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + splPrf = &SupplierWithCache{ + SupplierProfile: &engine.SupplierProfile{ + Tenant: "cgrates.org", + ID: "SPL_DESTINATION", + FilterIDs: []string{"*string:~Account:SpecialCase"}, + Sorting: utils.MetaLeastCost, + Suppliers: []*engine.Supplier{ + { + ID: "local", + RatingPlanIDs: []string{"RP_LOCAL"}, + Weight: 10, + }, + { + ID: "mobile", + RatingPlanIDs: []string{"RP_MOBILE"}, + FilterIDs: []string{"*destinations:~*req.Destination:DST_MOBILE"}, + Weight: 10, + }, + }, + Weight: 100, + }, + } + + var result string + if err := splSv1Rpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + + ev := &engine.ArgsGetSuppliers{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testV1SplsOneSupplierWithoutDestination", + Event: map[string]interface{}{ + utils.Account: "SpecialCase", + utils.Destination: "+24680", + utils.SetupTime: utils.MetaNow, + utils.Usage: "2m", + }, + }, + IgnoreErrors: true, + } + eSpls := engine.SortedSuppliers{ + ProfileID: "SPL_DESTINATION", + Sorting: utils.MetaLeastCost, + Count: 1, + SortedSuppliers: []*engine.SortedSupplier{ + { + SupplierID: "local", + SortingData: map[string]interface{}{ + utils.Cost: 0.0396, + "RatingPlanID": "RP_LOCAL", + 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)) + } + + //in case that we don't use ignore errors + //we get an error for the second supplier + ev.IgnoreErrors = false + if err := splSv1Rpc.Call(utils.SupplierSv1GetSuppliers, + ev, &suplsReply); err != nil { + t.Error(err) + } +} + func testV1SplSStopEngine(t *testing.T) { if err := engine.KillEngine(100); err != nil { t.Error(err) diff --git a/data/tariffplans/testit/DestinationRates.csv b/data/tariffplans/testit/DestinationRates.csv index f7d271400..03324a640 100644 --- a/data/tariffplans/testit/DestinationRates.csv +++ b/data/tariffplans/testit/DestinationRates.csv @@ -3,4 +3,7 @@ DR_ANY_1CNT,*any,RT_1CNT,*up,5,0, DR_ANY_2CNT,*any,RT_2CNT,*up,5,0, DR_SPECIAL_1002,DST_1002,RT_1CNT,*up,4,0, DR_FS_40CNT,DST_FS,RT_40CNT,*up,4,0, -DR_TEST_1,DST_1001,RT_TEST_1,*up,4,0, \ No newline at end of file +DR_TEST_1,DST_1001,RT_TEST_1,*up,4,0, +DR_MOBILE_1CNT,DST_MOBILE,RT_1CNT,*up,5,0, +DR_LOCAL_2CNT,DST_LOCAL,RT_2CNT,*up,5,0, +DR_LOCAL_2CNT,DST_MOBILE,RT_2CNT,*up,5,0, \ No newline at end of file diff --git a/data/tariffplans/testit/Destinations.csv b/data/tariffplans/testit/Destinations.csv index 57c34152b..a2f6c5a3d 100755 --- a/data/tariffplans/testit/Destinations.csv +++ b/data/tariffplans/testit/Destinations.csv @@ -3,5 +3,6 @@ DST_1002,1002 DST_FS,10 DST_DE_MOBILE,+49151 DST_1001,1001 - +DST_MOBILE,+135 +DST_LOCAL,+246 diff --git a/data/tariffplans/testit/RatingPlans.csv b/data/tariffplans/testit/RatingPlans.csv index 2dc953095..0109a889d 100644 --- a/data/tariffplans/testit/RatingPlans.csv +++ b/data/tariffplans/testit/RatingPlans.csv @@ -4,4 +4,6 @@ RP_SPECIAL_1002,DR_SPECIAL_1002,*any,10 RP_RETAIL1,DR_FS_40CNT,*any,10 RP_ANY2CNT,DR_ANY_2CNT,*any,10 RP_ANY1CNT,DR_ANY_1CNT,*any,10 -RP_TEST,DR_TEST_1,*any,10 \ No newline at end of file +RP_TEST,DR_TEST_1,*any,10 +RP_MOBILE,DR_MOBILE_1CNT,*any,10 +RP_LOCAL,DR_LOCAL_2CNT,*any,10 \ No newline at end of file