From 9b8d08dc0dc6b2ebf3cb4f234522c733699c671e Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 23 Sep 2019 04:47:31 -0400 Subject: [PATCH] Add ApierV1.GetRatingPlanIDs + test ( fixes #1692 ) --- apier/v1/apier.go | 20 +++++++++++++++++++- apier/v1/apier2_it_test.go | 25 +++++++++++++++++++++++-- utils/consts.go | 1 + 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 0e3d837f8..b65995882 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1254,7 +1254,7 @@ func (self *ApierV1) ComputeActionPlanIndexes(_ string, reply *string) (err erro return nil } -// GetActionPlanIDs returns list of attributeProfile IDs registered for a tenant +// GetActionPlanIDs returns list of ActionPlan IDs registered for a tenant func (apierV1 *ApierV1) GetActionPlanIDs(args utils.TenantArgWithPaginator, attrPrfIDs *[]string) error { prfx := utils.ACTION_PLAN_PREFIX keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(utils.ACTION_PLAN_PREFIX) @@ -1271,3 +1271,21 @@ func (apierV1 *ApierV1) GetActionPlanIDs(args utils.TenantArgWithPaginator, attr *attrPrfIDs = args.PaginateStringSlice(retIDs) return nil } + +// GetRatingPlanIDs returns list of RatingPlan IDs registered for a tenant +func (apierV1 *ApierV1) GetRatingPlanIDs(args utils.TenantArgWithPaginator, attrPrfIDs *[]string) error { + prfx := utils.RATING_PLAN_PREFIX + keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(utils.RATING_PLAN_PREFIX) + if err != nil { + return err + } + if len(keys) == 0 { + return utils.ErrNotFound + } + retIDs := make([]string, len(keys)) + for i, key := range keys { + retIDs[i] = key[len(prfx):] + } + *attrPrfIDs = args.PaginateStringSlice(retIDs) + return nil +} diff --git a/apier/v1/apier2_it_test.go b/apier/v1/apier2_it_test.go index 01a899a0c..9aecff5e5 100644 --- a/apier/v1/apier2_it_test.go +++ b/apier/v1/apier2_it_test.go @@ -26,6 +26,7 @@ import ( "net/rpc/jsonrpc" "path" "reflect" + "sort" "testing" "time" @@ -58,6 +59,7 @@ var sTestsAPIer = []func(t *testing.T){ testAPIerGetRatingPlanCost2, testAPIerGetRatingPlanCost3, testAPIerGetActionPlanIDs, + testAPIerGetRatingPlanIDs, testAPIerKillEngine, } @@ -277,13 +279,32 @@ func testAPIerGetActionPlanIDs(t *testing.T) { utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &reply); err != nil { t.Error(err) - } else if len(reply) != 1 { + } else if len(reply) != 1 { t.Errorf("Expected: 1 , received: <%+v>", len(reply)) - }else if reply[0]!="AP_PACKAGE_10"{ + } else if reply[0] != "AP_PACKAGE_10" { t.Errorf("Expected: AP_PACKAGE_10 , received: <%+v>", reply[0]) } } +func testAPIerGetRatingPlanIDs(t *testing.T) { + var reply []string + expected := []string{"RP_1002_LOW", "RP_1003", "RP_1001", "RP_SMS", "RP_1002"} + if err := apierRPC.Call(utils.ApierV1GetRatingPlanIDs, + utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, + &reply); err != nil { + t.Error(err) + } else if len(reply) != 5 { + t.Errorf("Expected: 5 , received: <%+v>", len(reply)) + } else { + sort.Strings(reply) + sort.Strings(expected) + if !reflect.DeepEqual(reply, expected) { + t.Errorf("Expected: <%+v> , received: <%+v>", expected, reply) + + } + } +} + func testAPIerKillEngine(t *testing.T) { if err := engine.KillEngine(*waitRater); err != nil { t.Error(err) diff --git a/utils/consts.go b/utils/consts.go index aa9c2bc53..b17c6aa19 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -811,6 +811,7 @@ const ( ApierV1GetAccountActionPlan = "ApierV1.GetAccountActionPlan" ApierV1ComputeActionPlanIndexes = "ApierV1.ComputeActionPlanIndexes" ApierV1GetActionPlanIDs = "ApierV1.GetActionPlanIDs" + ApierV1GetRatingPlanIDs = "ApierV1.GetRatingPlanIDs" ) const (