mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Adding ToJSON method in callcost, tests for MaxCallCost
This commit is contained in:
@@ -6,5 +6,5 @@ DR_1003_10CNT,DST_1003,RT_10CNT,*up,4,0,
|
||||
DR_FS_40CNT,DST_FS,RT_40CNT,*up,4,0,
|
||||
DR_FS_10CNT,DST_FS,RT_10CNT,*up,4,0,
|
||||
DR_SPECIAL_1002,DST_1002,RT_1CNT,*up,4,0,
|
||||
DR_1007_MAXCOST_DISC,DST_1007,RT_1CNT,*up,4,0.62,*disconnect
|
||||
DR_1007_MAXCOST_FREE,DST_1007,RT_1CNT,*up,4,0.62,*free
|
||||
DR_1007_MAXCOST_DISC,DST_1007,RT_1CNT_PER_SEC,*up,4,0.62,*disconnect
|
||||
DR_1007_MAXCOST_FREE,DST_1007,RT_1CNT_PER_SEC,*up,4,0.62,*free
|
||||
|
||||
|
@@ -6,3 +6,4 @@ RT_20CNT,0,0.1,60s,1s,60s
|
||||
RT_40CNT,0.8,0.4,60s,30s,0s
|
||||
RT_40CNT,0,0.2,60s,10s,60s
|
||||
RT_1CNT,0,0.01,60s,60s,0s
|
||||
RT_1CNT_PER_SEC,0,0.01,1s,1s,0s
|
||||
|
||||
|
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"time"
|
||||
@@ -161,3 +162,8 @@ func (cc *CallCost) GetLongestRounding() (roundingDecimals int, roundingMethod s
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (cc *CallCost) AsJSON() string {
|
||||
ccJson, _ := json.Marshal(cc)
|
||||
return string(ccJson)
|
||||
}
|
||||
|
||||
@@ -296,6 +296,67 @@ func TestTutLocalGetCosts(t *testing.T) {
|
||||
} else if cc.Cost != 1.3 {
|
||||
t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
||||
}
|
||||
tStart = time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC)
|
||||
cd = engine.CallDescriptor{
|
||||
Direction: "*out",
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "1001",
|
||||
Account: "1001",
|
||||
Destination: "1007",
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tStart.Add(time.Duration(50) * time.Second),
|
||||
}
|
||||
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
|
||||
t.Error("Got error on Responder.GetCost: ", err.Error())
|
||||
} else if cc.Cost != 0.5 {
|
||||
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
||||
}
|
||||
cd = engine.CallDescriptor{
|
||||
Direction: "*out",
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "1001",
|
||||
Account: "1001",
|
||||
Destination: "1007",
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tStart.Add(time.Duration(70) * time.Second),
|
||||
}
|
||||
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
|
||||
t.Error("Got error on Responder.GetCost: ", err.Error())
|
||||
} else if cc.Cost != 0.62 {
|
||||
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
||||
}
|
||||
cd = engine.CallDescriptor{
|
||||
Direction: "*out",
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "1002",
|
||||
Account: "1002",
|
||||
Destination: "1007",
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tStart.Add(time.Duration(50) * time.Second),
|
||||
}
|
||||
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
|
||||
t.Error("Got error on Responder.GetCost: ", err.Error())
|
||||
} else if cc.Cost != 0.5 {
|
||||
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
||||
}
|
||||
cd = engine.CallDescriptor{
|
||||
Direction: "*out",
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "1002",
|
||||
Account: "1002",
|
||||
Destination: "1007",
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tStart.Add(time.Duration(70) * time.Second),
|
||||
}
|
||||
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
|
||||
t.Error("Got error on Responder.GetCost: ", err.Error())
|
||||
} else if cc.Cost != 0.62 {
|
||||
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
||||
}
|
||||
}
|
||||
|
||||
// Check call costs
|
||||
|
||||
Reference in New Issue
Block a user