From dc59d6fdfc113a56da0fb7e7f6748350377d0720 Mon Sep 17 00:00:00 2001 From: andronache Date: Wed, 2 Dec 2020 11:12:20 +0200 Subject: [PATCH] Added more tests to engine/model_helpers --- engine/model_helpers_test.go | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index ec1562d82..be0adcd93 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -4870,3 +4870,106 @@ func TestModelHelpersAPItoRateProfileError3(t *testing.T) { t.Errorf("\n,\n Received <%+v>", err) } } + +func TestAPItoModelTPRateProfileNil(t *testing.T) { + testStruct := &utils.TPRateProfile{ + Rates: map[string]*utils.TPRate{}, + } + result := APItoModelTPRateProfile(testStruct) + if !reflect.DeepEqual(utils.ToJSON(result), "null") { + t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(result)) + } +} + +func TestAPItoModelTPRateProfileCase2(t *testing.T) { + testStruct := &utils.TPRateProfile{ + FilterIDs: []string{"test_string1", "test_string2"}, + ActivationInterval: &utils.TPActivationInterval{ + ActivationTime: "2014-07-29T15:00:00Z", + ExpiryTime: "2014-08-29T15:00:00Z", + }, + Rates: map[string]*utils.TPRate{"RT_CHRISTMAS": { + ID: "RT_CHRISTMAS", + FilterIDs: []string{"test_string1", "test_string2"}, + Weight: 30, + ActivationTime: "* * 24 12 *", + IntervalRates: []*utils.TPIntervalRate{ + { + IntervalStart: "0s", + RecurrentFee: 0.06, + Unit: "1m0s", + Increment: "1s", + }, + { + IntervalStart: "0s", + RecurrentFee: 0.06, + Unit: "1m0s", + Increment: "1s", + }, + }, + }, + }, + } + expected := "[{\"PK\":0,\"Tpid\":\"\",\"Tenant\":\"\",\"ID\":\"\",\"FilterIDs\":\"test_string1;test_string2\",\"ActivationInterval\":\"2014-07-29T15:00:00Z;2014-08-29T15:00:00Z\",\"Weight\":0,\"RoundingMethod\":\"\",\"RoundingDecimals\":0,\"MinCost\":0,\"MaxCost\":0,\"MaxCostStrategy\":\"\",\"RateID\":\"RT_CHRISTMAS\",\"RateFilterIDs\":\"test_string1;test_string2\",\"RateActivationStart\":\"* * 24 12 *\",\"RateWeight\":30,\"RateBlocker\":false,\"RateIntervalStart\":\"0s\",\"RateFixedFee\":0,\"RateRecurrentFee\":0.06,\"RateUnit\":\"1m0s\",\"RateIncrement\":\"1s\",\"CreatedAt\":\"0001-01-01T00:00:00Z\"},{\"PK\":0,\"Tpid\":\"\",\"Tenant\":\"\",\"ID\":\"\",\"FilterIDs\":\"\",\"ActivationInterval\":\"\",\"Weight\":0,\"RoundingMethod\":\"\",\"RoundingDecimals\":0,\"MinCost\":0,\"MaxCost\":0,\"MaxCostStrategy\":\"\",\"RateID\":\"RT_CHRISTMAS\",\"RateFilterIDs\":\"\",\"RateActivationStart\":\"\",\"RateWeight\":0,\"RateBlocker\":false,\"RateIntervalStart\":\"0s\",\"RateFixedFee\":0,\"RateRecurrentFee\":0.06,\"RateUnit\":\"1m0s\",\"RateIncrement\":\"1s\",\"CreatedAt\":\"0001-01-01T00:00:00Z\"}]" + result := APItoModelTPRateProfile(testStruct) + if !reflect.DeepEqual(expected, utils.ToJSON(result)) { + t.Errorf("\nExpecting <[{\"PK\":0,\"Tpid\":\"\",\"Tenant\":\"\",\"ID\":\"\",\"FilterIDs\":\"test_string1;test_string2\",\"ActivationInterval\":\"2014-07-29T15:00:00Z;2014-08-29T15:00:00Z\",\"Weight\":0,\"RoundingMethod\":\"\",\"RoundingDecimals\":0,\"MinCost\":0,\"MaxCost\":0,\"MaxCostStrategy\":\"\",\"RateID\":\"RT_CHRISTMAS\",\"RateFilterIDs\":\"test_string1;test_string2\",\"RateActivationStart\":\"* * 24 12 *\",\"RateWeight\":30,\"RateBlocker\":false,\"RateIntervalStart\":\"0s\",\"RateFixedFee\":0,\"RateRecurrentFee\":0.06,\"RateUnit\":\"1m0s\",\"RateIncrement\":\"1s\",\"CreatedAt\":\"0001-01-01T00:00:00Z\"},{\"PK\":0,\"Tpid\":\"\",\"Tenant\":\"\",\"ID\":\"\",\"FilterIDs\":\"\",\"ActivationInterval\":\"\",\"Weight\":0,\"RoundingMethod\":\"\",\"RoundingDecimals\":0,\"MinCost\":0,\"MaxCost\":0,\"MaxCostStrategy\":\"\",\"RateID\":\"RT_CHRISTMAS\",\"RateFilterIDs\":\"\",\"RateActivationStart\":\"\",\"RateWeight\":0,\"RateBlocker\":false,\"RateIntervalStart\":\"0s\",\"RateFixedFee\":0,\"RateRecurrentFee\":0.06,\"RateUnit\":\"1m0s\",\"RateIncrement\":\"1s\",\"CreatedAt\":\"0001-01-01T00:00:00Z\"}]>,\n Received <%+v>", utils.ToJSON(result)) + } +} + +func TestRateProfileMdlsAsTPRateProfileCase2(t *testing.T) { + testRPMdls := RateProfileMdls{&RateProfileMdl{ + PK: 0, + Tpid: "", + Tenant: "cgrates.org", + ID: "RP1", + FilterIDs: "*string:~*req.Subject:1001", + ActivationInterval: "2014-07-29T15:00:00Z;2014-08-29T15:00:00Z", + Weight: 1.2, + RoundingMethod: "*up", + RoundingDecimals: 4, + MinCost: 0.1, + MaxCost: 0.6, + MaxCostStrategy: "*free", + RateID: "RT_WEEK", + RateFilterIDs: "TEST_RateFilterIDs", + RateActivationStart: "* * * * 1-5", + RateWeight: 1.2, + RateBlocker: false, + RateIntervalStart: "1m", + RateRecurrentFee: 0.06, + RateUnit: "1m0s", + RateIncrement: "1s", + CreatedAt: time.Time{}, + }, + &RateProfileMdl{ + PK: 0, + Tpid: "", + Tenant: "cgrates.org", + ID: "RP1", + FilterIDs: "TEST_RateFilterIDs", + ActivationInterval: "2014-07-29T15:00:00Z", + Weight: 1.2, + RoundingMethod: "", + RoundingDecimals: 0, + MinCost: 0, + MaxCost: 0, + MaxCostStrategy: "", + RateID: "RT_WEEK", + RateFilterIDs: "", + RateActivationStart: "", + RateWeight: 1.3, + RateBlocker: false, + RateIntervalStart: "0s", + RateRecurrentFee: 0.12, + RateUnit: "1m0s", + RateIncrement: "1m0s", + CreatedAt: time.Time{}, + }, + } + result := testRPMdls.AsTPRateProfile() + expected := "[{\"TPid\":\"\",\"Tenant\":\"cgrates.org\",\"ID\":\"RP1\",\"FilterIDs\":[\"*string:~*req.Subject:1001\",\"TEST_RateFilterIDs\"],\"ActivationInterval\":{\"ActivationTime\":\"2014-07-29T15:00:00Z\",\"ExpiryTime\":\"\"},\"Weight\":1.2,\"RoundingMethod\":\"*up\",\"RoundingDecimals\":4,\"MinCost\":0.1,\"MaxCost\":0.6,\"MaxCostStrategy\":\"*free\",\"Rates\":{\"RT_WEEK\":{\"ID\":\"RT_WEEK\",\"FilterIDs\":[\"TEST_RateFilterIDs\"],\"ActivationTime\":\"* * * * 1-5\",\"Weight\":1.3,\"Blocker\":false,\"IntervalRates\":[{\"IntervalStart\":\"1m\",\"FixedFee\":0,\"Unit\":\"1m0s\",\"Increment\":\"1s\",\"RecurrentFee\":0.06},{\"IntervalStart\":\"0s\",\"FixedFee\":0,\"Unit\":\"1m0s\",\"Increment\":\"1m0s\",\"RecurrentFee\":0.12}]}}}]" + if !reflect.DeepEqual(utils.ToJSON(result), expected) { + t.Errorf("\nExpecting <[{\"TPid\":\"\",\"Tenant\":\"cgrates.org\",\"ID\":\"RP1\",\"FilterIDs\":[\"*string:~*req.Subject:1001\",\"TEST_RateFilterIDs\"],\"ActivationInterval\":{\"ActivationTime\":\"2014-07-29T15:00:00Z\",\"ExpiryTime\":\"\"},\"Weight\":1.2,\"RoundingMethod\":\"*up\",\"RoundingDecimals\":4,\"MinCost\":0.1,\"MaxCost\":0.6,\"MaxCostStrategy\":\"*free\",\"Rates\":{\"RT_WEEK\":{\"ID\":\"RT_WEEK\",\"FilterIDs\":[\"TEST_RateFilterIDs\"],\"ActivationTime\":\"* * * * 1-5\",\"Weight\":1.3,\"Blocker\":false,\"IntervalRates\":[{\"IntervalStart\":\"1m\",\"FixedFee\":0,\"Unit\":\"1m0s\",\"Increment\":\"1s\",\"RecurrentFee\":0.06},{\"IntervalStart\":\"0s\",\"FixedFee\":0,\"Unit\":\"1m0s\",\"Increment\":\"1m0s\",\"RecurrentFee\":0.12}]}}}]>,\n Received <%+v>", utils.ToJSON(result)) + } +}