ResetAccountActionTriggers has Executed attribute

This commit is contained in:
Radu Ioan Fericean
2016-05-03 15:54:15 +03:00
parent 3db05157ac
commit 2ee445abcf
2 changed files with 42 additions and 3 deletions

View File

@@ -129,7 +129,15 @@ func (self *ApierV1) RemoveAccountActionTriggers(attr AttrRemoveAccountActionTri
return nil
}
func (self *ApierV1) ResetAccountActionTriggers(attr AttrRemoveAccountActionTriggers, reply *string) error {
type AttrResetAccountActionTriggers struct {
Tenant string
Account string
GroupID string
UniqueID string
Executed bool
}
func (self *ApierV1) ResetAccountActionTriggers(attr AttrResetAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"Tenant", "Account"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
@@ -146,11 +154,13 @@ func (self *ApierV1) ResetAccountActionTriggers(attr AttrRemoveAccountActionTrig
if (attr.UniqueID == "" || at.UniqueID == attr.UniqueID) &&
(attr.GroupID == "" || at.ID == attr.GroupID) {
// reset action trigger
at.Executed = false
at.Executed = attr.Executed
}
}
account.ExecuteActionTriggers(nil)
if attr.Executed == false {
account.ExecuteActionTriggers(nil)
}
if err := self.AccountDb.SetAccount(account); err != nil {
return 0, err
}

View File

@@ -366,3 +366,32 @@ func TestTpRemActionsRefenced(t *testing.T) {
t.Error("no error on ApierV2.GetActions: ", err)
}
}
func TestApierResetAccountActionTriggers(t *testing.T) {
if !*testIntegration {
return
}
var acnt engine.Account
attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1005"}
if err := tpRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
t.Error(err)
} else if acnt.ActionTriggers[0].Executed == true {
t.Errorf("wrong action trigger executed flag: %s", utils.ToIJSON(acnt.ActionTriggers))
}
var reply string
if err := tpRPC.Call("ApierV2.ResetAccountActionTriggers", v1.AttrResetAccountActionTriggers{
Tenant: "cgrates.org",
Account: "1005",
GroupID: "STANDARD_TRIGGERS",
Executed: true,
}, &reply); err != nil {
t.Error("Error on ApierV2.ResetAccountActionTriggers: ", err.Error())
} else if reply != utils.OK {
t.Errorf("Calling ApierV2.ResetAccountActionTriggers got reply: %s", reply)
}
if err := tpRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
t.Error(err)
} else if acnt.ActionTriggers[0].Executed == false {
t.Errorf("wrong action trigger executed flag: %s", utils.ToIJSON(acnt.ActionTriggers))
}
}