mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added more tests to engine/model_helpers
This commit is contained in:
committed by
Dan Christian Bogos
parent
d220ab88b9
commit
dc59d6fdfc
@@ -4870,3 +4870,106 @@ func TestModelHelpersAPItoRateProfileError3(t *testing.T) {
|
||||
t.Errorf("\n<time: invalid duration \"cat\">,\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 <null>,\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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user