From 2ee445abcfdf5453e4a6f5288a3395db2d3f2886 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 3 May 2016 15:54:15 +0300 Subject: [PATCH] ResetAccountActionTriggers has Executed attribute --- apier/v1/triggers.go | 16 +++++++++++++--- general_tests/tp_it_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/apier/v1/triggers.go b/apier/v1/triggers.go index b6c6a3f5f..93d9e9ed1 100644 --- a/apier/v1/triggers.go +++ b/apier/v1/triggers.go @@ -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 } diff --git a/general_tests/tp_it_test.go b/general_tests/tp_it_test.go index 8fb9ca7b2..0a1681ec1 100644 --- a/general_tests/tp_it_test.go +++ b/general_tests/tp_it_test.go @@ -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)) + } +}