mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Renamed resetAccount action (and added test)
This commit is contained in:
committed by
Dan Christian Bogos
parent
7ea1c0c719
commit
bb59a66e47
@@ -107,7 +107,7 @@ func getActionFunc(typ string) (actionTypeFunc, bool) {
|
||||
utils.MetaRemoveSessionCosts: removeSessionCosts,
|
||||
utils.MetaRemoveExpired: removeExpired,
|
||||
utils.MetaPostEvent: postEvent,
|
||||
utils.MetaCDRAccount: resetAccount,
|
||||
utils.MetaCDRAccount: resetAccountCDR,
|
||||
}
|
||||
f, exists := actionFuncMap[typ]
|
||||
return f, exists
|
||||
@@ -1051,7 +1051,8 @@ func postEvent(ub *Account, a *Action, acs Actions, extraData interface{}) error
|
||||
return err
|
||||
}
|
||||
|
||||
func resetAccount(ub *Account, action *Action, acts Actions, _ interface{}) error {
|
||||
// resetAccountCDR resets the account out of values from CDR
|
||||
func resetAccountCDR(ub *Account, action *Action, acts Actions, _ interface{}) error {
|
||||
if ub == nil {
|
||||
return errors.New("nil account")
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ var (
|
||||
testActionsitThresholdCgrRpcAction,
|
||||
testActionsitThresholdPostEvent,
|
||||
testActionsitSetSDestinations,
|
||||
testActionsitresetAccountCDR,
|
||||
testActionsitStopCgrEngine,
|
||||
}
|
||||
)
|
||||
@@ -809,6 +810,97 @@ func testActionsitSetSDestinations(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func testActionsitresetAccountCDR(t *testing.T) {
|
||||
var reply string
|
||||
account := "123456789"
|
||||
|
||||
attrsSetAccount := &utils.AttrSetAccount{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "123456789",
|
||||
}
|
||||
if err := actsLclRpc.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.SetAccount: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling APIerSv1.SetAccount received: %s", reply)
|
||||
}
|
||||
|
||||
attrsAA := &utils.AttrSetActions{
|
||||
ActionsId: "resetAccountCDR",
|
||||
Actions: []*utils.TPAction{
|
||||
{Identifier: utils.MetaCDRAccount, ExpiryTime: utils.UNLIMITED, Weight: 20.0},
|
||||
},
|
||||
}
|
||||
if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
|
||||
t.Error("Got error on APIerSv2.SetActions: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling APIerSv2.SetActions received: %s", reply)
|
||||
}
|
||||
|
||||
var acc Account
|
||||
attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: account}
|
||||
var uuid string
|
||||
if err := actsLclRpc.Call(utils.APIerSv2GetAccount, attrs2, &acc); err != nil {
|
||||
t.Error("Got error on APIerSv1.GetAccount: ", err.Error())
|
||||
} else {
|
||||
voice := acc.BalanceMap[utils.VOICE]
|
||||
for _, u := range voice {
|
||||
uuid = u.Uuid
|
||||
break
|
||||
}
|
||||
}
|
||||
args := &CDRWithArgDispatcher{
|
||||
CDR: &CDR{
|
||||
Tenant: "cgrates.org",
|
||||
OriginID: "testDsp",
|
||||
OriginHost: "192.168.1.1",
|
||||
Source: "testDsp",
|
||||
RequestType: utils.META_RATED,
|
||||
RunID: utils.MetaDefault,
|
||||
PreRated: true,
|
||||
Account: account,
|
||||
Subject: account,
|
||||
Destination: "1002",
|
||||
AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
|
||||
Usage: time.Duration(2) * time.Minute,
|
||||
CostDetails: &EventCost{
|
||||
CGRID: utils.UUIDSha1Prefix(),
|
||||
RunID: utils.MetaDefault,
|
||||
AccountSummary: &AccountSummary{
|
||||
Tenant: "cgrates.org",
|
||||
ID: account,
|
||||
BalanceSummaries: []*BalanceSummary{
|
||||
{
|
||||
UUID: uuid,
|
||||
ID: "ID",
|
||||
Type: utils.VOICE,
|
||||
Value: float64(10 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := actsLclRpc.Call(utils.CDRsV1ProcessCDR, args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", Account: account, ActionsId: attrsAA.ActionsId}
|
||||
if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply)
|
||||
}
|
||||
|
||||
if err := actsLclRpc.Call(utils.APIerSv2GetAccount, attrs2, &acc); err != nil {
|
||||
t.Error("Got error on APIerSv1.GetAccount: ", err.Error())
|
||||
} else if tv := acc.BalanceMap[utils.VOICE].GetTotalValue(); tv != float64(10*time.Second) {
|
||||
t.Errorf("Calling APIerSv1.GetBalance expected: %f, received: %f", float64(10*time.Second), tv)
|
||||
}
|
||||
}
|
||||
|
||||
func testActionsitStopCgrEngine(t *testing.T) {
|
||||
if err := KillEngine(*waitRater); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -843,7 +843,7 @@ const (
|
||||
MetaRemoveSessionCosts = "*remove_session_costs"
|
||||
MetaRemoveExpired = "*remove_expired"
|
||||
MetaPostEvent = "*post_event"
|
||||
MetaCDRAccount = "*cdr_account"
|
||||
MetaCDRAccount = "*reset_account_cdr"
|
||||
)
|
||||
|
||||
// Migrator Metas
|
||||
|
||||
Reference in New Issue
Block a user