Add test for Update Blocker flag for balance

This commit is contained in:
TeoV
2019-07-18 12:52:03 +03:00
committed by Dan Christian Bogos
parent ab38aba044
commit 54a6639b67

View File

@@ -24,6 +24,7 @@ import (
"net/rpc/jsonrpc"
"path"
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
@@ -47,6 +48,7 @@ var sTestsActions = []func(t *testing.T){
testActionsSetSMCosts,
testActionsExecuteRemoveSMCos1,
testActionsExecuteRemoveSMCos2,
testActionsUpdateBalance,
testActionsKillEngine,
}
@@ -223,6 +225,54 @@ func testActionsExecuteRemoveSMCos2(t *testing.T) {
}
}
func testActionsUpdateBalance(t *testing.T) {
var reply string
attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "testAcc"}
if err := actsRPC.Call("ApierV1.SetAccount", attrsSetAccount, &reply); err != nil {
t.Error("Got error on ApierV1.SetAccount: ", err.Error())
} else if reply != utils.OK {
t.Errorf("Calling ApierV1.SetAccount received: %s", reply)
}
topupAction := &utils.AttrSetActions{ActionsId: "ACT_TOPUP_RST", Actions: []*utils.TPAction{
{Identifier: TOPUP, BalanceId: "test", BalanceType: utils.MONETARY, Units: "5", ExpiryTime: UNLIMITED, Weight: 20.0},
}}
if err := actsRPC.Call("ApierV2.SetActions", topupAction, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
t.Error("Got error on ApierV2.SetActions: ", err.Error())
} else if reply != utils.OK {
t.Errorf("Calling ApierV2.SetActions received: %s", reply)
}
changeBlockerAction := &utils.AttrSetActions{ActionsId: "ACT_BAL_UPDT", Actions: []*utils.TPAction{
{Identifier: SET_BALANCE, BalanceId: "test", BalanceBlocker: "true"},
}}
if err := actsRPC.Call("ApierV2.SetActions", changeBlockerAction, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
t.Error("Got error on ApierV2.SetActions: ", err.Error())
} else if reply != utils.OK {
t.Errorf("Calling ApierV2.SetActions received: %s", reply)
}
attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: topupAction.ActionsId}
if err := actsRPC.Call("ApierV1.ExecuteAction", attrsEA, &reply); err != nil {
t.Error("Got error on ApierV1.ExecuteAction: ", err.Error())
} else if reply != utils.OK {
t.Errorf("Calling ApierV1.ExecuteAction received: %s", reply)
}
time.Sleep(10 * time.Millisecond)
attrsEA2 := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: changeBlockerAction.ActionsId}
if err := actsRPC.Call("ApierV1.ExecuteAction", attrsEA2, &reply); err != nil {
t.Error("Got error on ApierV1.ExecuteAction: ", err.Error())
} else if reply != utils.OK {
t.Errorf("Calling ApierV1.ExecuteAction received: %s", reply)
}
var acc Account
attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testAcc"}
if err := actsRPC.Call("ApierV2.GetAccount", attrs2, &acc); err != nil {
t.Error("Got error on ApierV1.GetAccount: ", err.Error())
} else if acc.BalanceMap[utils.MONETARY][0].ID != "test" {
t.Errorf("Expected test result received %v ", acc.BalanceMap[utils.MONETARY][0].ID)
} else if acc.BalanceMap[utils.MONETARY][0].Blocker != true {
t.Errorf("Expected true result received %v ", acc.BalanceMap[utils.MONETARY][0].Blocker)
}
}
func testActionsKillEngine(t *testing.T) {
if err := KillEngine(100); err != nil {
t.Error(err)