From 0880637453f9d86ec397b53365c5e1a9f96e0075 Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 1 Jul 2020 11:17:04 +0300 Subject: [PATCH] Add test for RemoveRateProfileRates --- apier/v1/rateprofiles.go | 2 +- apier/v1/rateprofiles_it_test.go | 171 +++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-) diff --git a/apier/v1/rateprofiles.go b/apier/v1/rateprofiles.go index bbaba2608..95720e1e6 100644 --- a/apier/v1/rateprofiles.go +++ b/apier/v1/rateprofiles.go @@ -143,7 +143,7 @@ type RemoveRPrfRates struct { } func (apierSv1 *APIerSv1) RemoveRateProfileRates(args *RemoveRPrfRates, reply *string) (err error) { - if missing := utils.MissingStructFields(args, []string{"Tenant", "ID", "RateIDs"}); len(missing) != 0 { + if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } if err := apierSv1.DataManager.RemoveRateProfileRates(args.Tenant, args.ID, args.RateIDs, true); err != nil { diff --git a/apier/v1/rateprofiles_it_test.go b/apier/v1/rateprofiles_it_test.go index 66805deea..d00f07815 100644 --- a/apier/v1/rateprofiles_it_test.go +++ b/apier/v1/rateprofiles_it_test.go @@ -50,6 +50,7 @@ var ( testV1RatePrfRemoveRateProfile, testV1RatePrfNotFound, testV1RatePrfSetRateProfileRates, + testV1RatePrfRemoveRateProfileRates, testV1RatePing, testV1RatePrfStopEngine, } @@ -378,6 +379,176 @@ func testV1RatePrfSetRateProfileRates(t *testing.T) { } +func testV1RatePrfRemoveRateProfileRates(t *testing.T) { + rPrf := &engine.RateProfile{ + Tenant: "cgrates.org", + ID: "SpecialRate", + FilterIDs: []string{"*string:~*req.Subject:1001"}, + Weight: 0, + ConnectFee: 0.1, + RoundingMethod: "*up", + RoundingDecimals: 4, + MinCost: 0.1, + MaxCost: 0.6, + MaxCostStrategy: "*free", + Rates: map[string]*engine.Rate{ + "RT_WEEK": &engine.Rate{ + ID: "RT_WEEK", + Weight: 0, + ActivationStart: "* * * * 1-5", + IntervalRates: []*engine.IntervalRate{ + &engine.IntervalRate{ + IntervalStart: time.Duration(0 * time.Second), + Value: 0.12, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Minute), + }, + &engine.IntervalRate{ + IntervalStart: time.Duration(1 * time.Minute), + Value: 0.06, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Second), + }, + }, + }, + "RT_WEEKEND": &engine.Rate{ + ID: "RT_WEEKEND", + Weight: 10, + ActivationStart: "* * * * 0,6", + IntervalRates: []*engine.IntervalRate{ + &engine.IntervalRate{ + IntervalStart: time.Duration(0 * time.Second), + Value: 0.06, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Second), + }, + }, + }, + "RT_CHRISTMAS": &engine.Rate{ + ID: "RT_CHRISTMAS", + Weight: 30, + ActivationStart: "* * 24 12 *", + IntervalRates: []*engine.IntervalRate{ + &engine.IntervalRate{ + IntervalStart: time.Duration(0 * time.Second), + Value: 0.06, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Second), + }, + }, + }, + }, + } + var reply string + if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfile, + &RateProfileWithCache{ + RateProfileWithArgDispatcher: &engine.RateProfileWithArgDispatcher{ + RateProfile: rPrf}, + }, &reply); err != nil { + t.Fatal(err) + } else if reply != utils.OK { + t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply) + } + + if err := ratePrfRpc.Call(utils.APIerSv1RemoveRateProfileRates, + &RemoveRPrfRates{ + Tenant: "cgrates.org", + ID: "SpecialRate", + RateIDs: []string{"RT_WEEKEND"}, + }, &reply); err != nil { + t.Fatal(err) + } else if reply != utils.OK { + t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply) + } + + rPrfUpdated := &engine.RateProfile{ + Tenant: "cgrates.org", + ID: "SpecialRate", + FilterIDs: []string{"*string:~*req.Subject:1001"}, + Weight: 0, + ConnectFee: 0.1, + RoundingMethod: "*up", + RoundingDecimals: 4, + MinCost: 0.1, + MaxCost: 0.6, + MaxCostStrategy: "*free", + Rates: map[string]*engine.Rate{ + "RT_WEEK": &engine.Rate{ + ID: "RT_WEEK", + Weight: 0, + ActivationStart: "* * * * 1-5", + IntervalRates: []*engine.IntervalRate{ + &engine.IntervalRate{ + IntervalStart: time.Duration(0 * time.Second), + Value: 0.12, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Minute), + }, + &engine.IntervalRate{ + IntervalStart: time.Duration(1 * time.Minute), + Value: 0.06, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Second), + }, + }, + }, + "RT_CHRISTMAS": &engine.Rate{ + ID: "RT_CHRISTMAS", + Weight: 30, + ActivationStart: "* * 24 12 *", + IntervalRates: []*engine.IntervalRate{ + &engine.IntervalRate{ + IntervalStart: time.Duration(0 * time.Second), + Value: 0.06, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Second), + }, + }, + }, + }, + } + var rply *engine.RateProfile + if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile, + utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "SpecialRate"}}, &rply); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rPrfUpdated, rply) { + t.Errorf("Expecting: %+v, \n received: %+v", + utils.ToJSON(rPrfUpdated), utils.ToJSON(rply)) + } + + if err := ratePrfRpc.Call(utils.APIerSv1RemoveRateProfileRates, + &RemoveRPrfRates{ + Tenant: "cgrates.org", + ID: "SpecialRate", + }, &reply); err != nil { + t.Fatal(err) + } else if reply != utils.OK { + t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply) + } + + rPrfUpdated2 := &engine.RateProfile{ + Tenant: "cgrates.org", + ID: "SpecialRate", + FilterIDs: []string{"*string:~*req.Subject:1001"}, + Weight: 0, + ConnectFee: 0.1, + RoundingMethod: "*up", + RoundingDecimals: 4, + MinCost: 0.1, + MaxCost: 0.6, + MaxCostStrategy: "*free", + Rates: map[string]*engine.Rate{}, + } + var rply2 *engine.RateProfile + if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile, + utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "SpecialRate"}}, &rply2); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rPrfUpdated2, rply2) { + t.Errorf("Expecting: %+v, \n received: %+v", + utils.ToJSON(rPrfUpdated2), utils.ToJSON(rply2)) + } +} + func testV1RatePing(t *testing.T) { var resp string if err := ratePrfRpc.Call(utils.RateSv1Ping, new(utils.CGREvent), &resp); err != nil {