mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 07:08:45 +05:00
Merge pull request #1831 from TeoV/master
Add test for Refund from CDRS
This commit is contained in:
@@ -44,6 +44,8 @@ var sTestsCDRsIT = []func(t *testing.T){
|
||||
testV1CDRsRpcConn,
|
||||
testV1CDRsLoadTariffPlanFromFolder,
|
||||
testV1CDRsProcessEventWithRefund,
|
||||
testV1CDRsRefundOutOfSessionCost,
|
||||
testV1CDRsRefundCDR,
|
||||
testV1CDRsKillEngine,
|
||||
}
|
||||
|
||||
@@ -242,6 +244,288 @@ func testV1CDRsProcessEventWithRefund(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
func testV1CDRsRefundOutOfSessionCost(t *testing.T) {
|
||||
//create a sessionCost and store it into storDB
|
||||
var acnt *engine.Account
|
||||
acntAttrs := &utils.AttrGetAccount{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "testV1CDRsRefundOutOfSessionCost"}
|
||||
attrSetBalance := utils.AttrSetBalance{
|
||||
Tenant: acntAttrs.Tenant,
|
||||
Account: acntAttrs.Account,
|
||||
BalanceType: utils.MONETARY,
|
||||
Balance: map[string]interface{}{
|
||||
utils.ID: utils.MetaDefault,
|
||||
utils.Value: 123,
|
||||
utils.Weight: 20,
|
||||
},
|
||||
}
|
||||
var reply string
|
||||
if err := cdrsRpc.Call(utils.ApierV1SetBalance, attrSetBalance, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("received: %s", reply)
|
||||
}
|
||||
|
||||
exp := 123.0
|
||||
if err := cdrsRpc.Call(utils.ApierV2GetAccount, acntAttrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if rply := acnt.BalanceMap[utils.MONETARY].GetTotalValue(); rply != exp {
|
||||
t.Errorf("Expecting: %v, received: %v", exp, rply)
|
||||
}
|
||||
balanceUuid := acnt.BalanceMap[utils.MONETARY][0].Uuid
|
||||
|
||||
attr := &engine.AttrCDRSStoreSMCost{
|
||||
Cost: &engine.SMCost{
|
||||
CGRID: "test1",
|
||||
RunID: utils.MetaDefault,
|
||||
OriginID: "testV1CDRsRefundOutOfSessionCost",
|
||||
CostSource: utils.MetaSessionS,
|
||||
Usage: time.Duration(3 * time.Minute),
|
||||
CostDetails: &engine.EventCost{
|
||||
CGRID: "test1",
|
||||
RunID: utils.MetaDefault,
|
||||
StartTime: time.Date(2017, 1, 9, 16, 18, 21, 0, time.UTC),
|
||||
Usage: utils.DurationPointer(time.Duration(3 * time.Minute)),
|
||||
Cost: utils.Float64Pointer(2.3),
|
||||
Charges: []*engine.ChargingInterval{
|
||||
&engine.ChargingInterval{
|
||||
RatingID: "c1a5ab9",
|
||||
Increments: []*engine.ChargingIncrement{
|
||||
&engine.ChargingIncrement{
|
||||
Usage: time.Duration(2 * time.Minute),
|
||||
Cost: 2.0,
|
||||
AccountingID: "a012888",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
&engine.ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
AccountingID: "44d6c02",
|
||||
CompressFactor: 60,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
AccountSummary: &engine.AccountSummary{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testV1CDRsRefundOutOfSessionCost",
|
||||
BalanceSummaries: []*engine.BalanceSummary{
|
||||
&engine.BalanceSummary{
|
||||
UUID: balanceUuid,
|
||||
Type: utils.MONETARY,
|
||||
Value: 50,
|
||||
},
|
||||
},
|
||||
AllowNegative: false,
|
||||
Disabled: false,
|
||||
},
|
||||
Rating: engine.Rating{
|
||||
"c1a5ab9": &engine.RatingUnit{
|
||||
ConnectFee: 0.1,
|
||||
RoundingMethod: "*up",
|
||||
RoundingDecimals: 5,
|
||||
RatesID: "ec1a177",
|
||||
RatingFiltersID: "43e77dc",
|
||||
},
|
||||
},
|
||||
Accounting: engine.Accounting{
|
||||
"a012888": &engine.BalanceCharge{
|
||||
AccountID: "cgrates.org:testV1CDRsRefundOutOfSessionCost",
|
||||
BalanceUUID: balanceUuid,
|
||||
Units: 120.7,
|
||||
},
|
||||
"44d6c02": &engine.BalanceCharge{
|
||||
AccountID: "cgrates.org:testV1CDRsRefundOutOfSessionCost",
|
||||
BalanceUUID: balanceUuid,
|
||||
Units: 120.7,
|
||||
},
|
||||
},
|
||||
Rates: engine.ChargedRates{
|
||||
"ec1a177": engine.RateGroups{
|
||||
&engine.Rate{
|
||||
GroupIntervalStart: time.Duration(0),
|
||||
Value: 0.01,
|
||||
RateIncrement: time.Duration(1 * time.Minute),
|
||||
RateUnit: time.Duration(1 * time.Second)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := cdrsRpc.Call(utils.CDRsV1StoreSessionCost,
|
||||
attr, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("received: %s", reply)
|
||||
}
|
||||
|
||||
argsEv := &engine.ArgV1ProcessEvent{
|
||||
Flags: []string{utils.MetaRALs},
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: "test1",
|
||||
utils.RunID: utils.MetaDefault,
|
||||
utils.OriginID: "testV1CDRsRefundOutOfSessionCost",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.Account: "testV1CDRsRefundOutOfSessionCost",
|
||||
utils.Destination: "+4986517174963",
|
||||
utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
|
||||
utils.Usage: time.Duration(123) * time.Minute,
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply received: ", reply)
|
||||
}
|
||||
|
||||
// Initial the balance was 123.0
|
||||
// after refunc the balance become 123.0+2.3=125.3
|
||||
exp = 124.0454
|
||||
if err := cdrsRpc.Call(utils.ApierV2GetAccount, acntAttrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if rply := acnt.BalanceMap[utils.MONETARY].GetTotalValue(); rply != exp {
|
||||
t.Errorf("Expecting: %v, received: %v", exp, rply)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1CDRsRefundCDR(t *testing.T) {
|
||||
//create a sessionCost and store it into storDB
|
||||
var acnt *engine.Account
|
||||
acntAttrs := &utils.AttrGetAccount{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "testV1CDRsRefundCDR"}
|
||||
attrSetBalance := utils.AttrSetBalance{
|
||||
Tenant: acntAttrs.Tenant,
|
||||
Account: acntAttrs.Account,
|
||||
BalanceType: utils.MONETARY,
|
||||
Balance: map[string]interface{}{
|
||||
utils.ID: utils.MetaDefault,
|
||||
utils.Value: 123,
|
||||
utils.Weight: 20,
|
||||
},
|
||||
}
|
||||
var reply string
|
||||
if err := cdrsRpc.Call(utils.ApierV1SetBalance, attrSetBalance, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("received: %s", reply)
|
||||
}
|
||||
|
||||
exp := 123.0
|
||||
if err := cdrsRpc.Call(utils.ApierV2GetAccount, acntAttrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if rply := acnt.BalanceMap[utils.MONETARY].GetTotalValue(); rply != exp {
|
||||
t.Errorf("Expecting: %v, received: %v", exp, rply)
|
||||
}
|
||||
|
||||
balanceUuid := acnt.BalanceMap[utils.MONETARY][0].Uuid
|
||||
|
||||
argsEv := &engine.ArgV1ProcessEvent{
|
||||
Flags: []string{utils.MetaRefund},
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
Event: map[string]interface{}{
|
||||
utils.RunID: utils.MetaDefault,
|
||||
utils.OriginID: "testV1CDRsRefundCDR",
|
||||
utils.RequestType: utils.META_PSEUDOPREPAID,
|
||||
utils.Account: "testV1CDRsRefundCDR",
|
||||
utils.Destination: "+4986517174963",
|
||||
utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
|
||||
utils.Usage: time.Duration(10) * time.Minute,
|
||||
utils.CostDetails: &engine.EventCost{
|
||||
CGRID: "test1",
|
||||
RunID: utils.MetaDefault,
|
||||
StartTime: time.Date(2017, 1, 9, 16, 18, 21, 0, time.UTC),
|
||||
Usage: utils.DurationPointer(time.Duration(3 * time.Minute)),
|
||||
Cost: utils.Float64Pointer(2.3),
|
||||
Charges: []*engine.ChargingInterval{
|
||||
&engine.ChargingInterval{
|
||||
RatingID: "c1a5ab9",
|
||||
Increments: []*engine.ChargingIncrement{
|
||||
&engine.ChargingIncrement{
|
||||
Usage: time.Duration(2 * time.Minute),
|
||||
Cost: 2.0,
|
||||
AccountingID: "a012888",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
&engine.ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
AccountingID: "44d6c02",
|
||||
CompressFactor: 60,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
AccountSummary: &engine.AccountSummary{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testV1CDRsRefundCDR",
|
||||
BalanceSummaries: []*engine.BalanceSummary{
|
||||
&engine.BalanceSummary{
|
||||
UUID: balanceUuid,
|
||||
Type: utils.MONETARY,
|
||||
Value: 50,
|
||||
},
|
||||
},
|
||||
AllowNegative: false,
|
||||
Disabled: false,
|
||||
},
|
||||
Rating: engine.Rating{
|
||||
"c1a5ab9": &engine.RatingUnit{
|
||||
ConnectFee: 0.1,
|
||||
RoundingMethod: "*up",
|
||||
RoundingDecimals: 5,
|
||||
RatesID: "ec1a177",
|
||||
RatingFiltersID: "43e77dc",
|
||||
},
|
||||
},
|
||||
Accounting: engine.Accounting{
|
||||
"a012888": &engine.BalanceCharge{
|
||||
AccountID: "cgrates.org:testV1CDRsRefundCDR",
|
||||
BalanceUUID: balanceUuid,
|
||||
Units: 120.7,
|
||||
},
|
||||
"44d6c02": &engine.BalanceCharge{
|
||||
AccountID: "cgrates.org:testV1CDRsRefundCDR",
|
||||
BalanceUUID: balanceUuid,
|
||||
Units: 120.7,
|
||||
},
|
||||
},
|
||||
Rates: engine.ChargedRates{
|
||||
"ec1a177": engine.RateGroups{
|
||||
&engine.Rate{
|
||||
GroupIntervalStart: time.Duration(0),
|
||||
Value: 0.01,
|
||||
RateIncrement: time.Duration(1 * time.Minute),
|
||||
RateUnit: time.Duration(1 * time.Second)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply received: ", reply)
|
||||
}
|
||||
|
||||
// Initial the balance was 123.0
|
||||
// after refund the balance become 123.0 + 2.3 = 125.3
|
||||
exp = 125.3
|
||||
if err := cdrsRpc.Call(utils.ApierV2GetAccount, acntAttrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if rply := acnt.BalanceMap[utils.MONETARY].GetTotalValue(); rply != exp {
|
||||
t.Errorf("Expecting: %v, received: %v", exp, rply)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1CDRsKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(*waitRater); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -797,10 +797,7 @@ func (cdrS *CDRServer) V1ProcessEvent(arg *ArgV1ProcessEvent, reply *string) (er
|
||||
}
|
||||
var refund bool
|
||||
if flgs.HasKey(utils.MetaRefund) {
|
||||
reRate = flgs.GetBool(utils.MetaRefund)
|
||||
if reRate {
|
||||
ralS = true
|
||||
}
|
||||
refund = flgs.GetBool(utils.MetaRefund)
|
||||
}
|
||||
// end of processing options
|
||||
|
||||
|
||||
@@ -1355,21 +1355,19 @@ const (
|
||||
|
||||
// Cdrs APIs
|
||||
const (
|
||||
CDRsV1 = "CDRsV1"
|
||||
CDRsV1GetCDRsCount = "CDRsV1.GetCDRsCount"
|
||||
CDRsV1RateCDRs = "CDRsV1.RateCDRs"
|
||||
CDRsV1GetCDRs = "CDRsV1.GetCDRs"
|
||||
CDRsV1ProcessCDR = "CDRsV1.ProcessCDR"
|
||||
CDRsV1ProcessExternalCDR = "CDRsV1.ProcessExternalCDR"
|
||||
CDRsV1StoreSessionCost = "CDRsV1.StoreSessionCost"
|
||||
CDRsV1ProcessEvent = "CDRsV1.ProcessEvent"
|
||||
CDRsV1Ping = "CDRsV1.Ping"
|
||||
CDRsV2 = "CDRsV2"
|
||||
CDRsV2StoreSessionCost = "CDRsV2.StoreSessionCost"
|
||||
CdrsV2ProcessExternalCdr = "CdrsV2.ProcessExternalCdr"
|
||||
CdrsV2ProcessCdr = "CdrsV2.ProcessCdr"
|
||||
CDRStatsV1GetQueue = "CDRStatsV1.GetQueue"
|
||||
SMGenericV2InitiateSession = "SMGenericV2.InitiateSession"
|
||||
CDRsV1 = "CDRsV1"
|
||||
CDRsV1GetCDRsCount = "CDRsV1.GetCDRsCount"
|
||||
CDRsV1RateCDRs = "CDRsV1.RateCDRs"
|
||||
CDRsV1GetCDRs = "CDRsV1.GetCDRs"
|
||||
CDRsV1ProcessCDR = "CDRsV1.ProcessCDR"
|
||||
CDRsV1ProcessExternalCDR = "CDRsV1.ProcessExternalCDR"
|
||||
CDRsV1StoreSessionCost = "CDRsV1.StoreSessionCost"
|
||||
CDRsV1ProcessEvent = "CDRsV1.ProcessEvent"
|
||||
CDRsV1Ping = "CDRsV1.Ping"
|
||||
CDRsV2 = "CDRsV2"
|
||||
CDRsV2StoreSessionCost = "CDRsV2.StoreSessionCost"
|
||||
CdrsV2ProcessExternalCdr = "CdrsV2.ProcessExternalCdr"
|
||||
CdrsV2ProcessCdr = "CdrsV2.ProcessCdr"
|
||||
)
|
||||
|
||||
// Scheduler
|
||||
|
||||
Reference in New Issue
Block a user