mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 08:38:45 +05:00
@@ -489,39 +489,35 @@ func (ub *Account) executeActionTriggers(a *Action) {
|
||||
for _, mb := range uc.Balances {
|
||||
if strings.HasPrefix(at.ThresholdType, "*max") {
|
||||
if mb.MatchActionTrigger(at) && mb.GetValue() >= at.ThresholdValue {
|
||||
// run the actions
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
} else { //MIN
|
||||
if mb.MatchActionTrigger(at) && mb.GetValue() <= at.ThresholdValue {
|
||||
// run the actions
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if at.ThresholdType == utils.TRIGGER_MIN_BALANCE || at.ThresholdType == utils.TRIGGER_MAX_BALANCE { // BALANCE THRESHOLD
|
||||
} else { // BALANCE
|
||||
for _, b := range ub.BalanceMap[at.BalanceType] {
|
||||
if !b.dirty { // do not check clean balances
|
||||
if !b.dirty && at.ThresholdType != utils.TRIGGER_EXP_BALANCE { // do not check clean balances
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(at.ThresholdType, "*max") {
|
||||
switch at.ThresholdType {
|
||||
case utils.TRIGGER_MAX_BALANCE:
|
||||
|
||||
if b.MatchActionTrigger(at) && b.GetValue() >= at.ThresholdValue {
|
||||
// run the actions
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
} else { //MIN
|
||||
case utils.TRIGGER_MIN_BALANCE:
|
||||
if b.MatchActionTrigger(at) && b.GetValue() <= at.ThresholdValue {
|
||||
// run the actions
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if at.ThresholdType == utils.TRIGGER_EXP_BALANCE {
|
||||
for _, b := range ub.BalanceMap[at.BalanceType] {
|
||||
if b.MatchActionTrigger(at) && b.IsExpired() {
|
||||
at.Execute(ub, nil)
|
||||
case utils.TRIGGER_EXP_BALANCE:
|
||||
if b.MatchActionTrigger(at) && b.IsExpired() {
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -963,7 +963,24 @@ func TestAccountExecuteTriggeredDayWeek(t *testing.T) {
|
||||
ub.UnitCounters[0].Balances[1].Value != 1 {
|
||||
t.Error("Error reseting both counters", ub.UnitCounters[0].Balances[0].Value, ub.UnitCounters[0].Balances[1].Value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountExpActionTrigger(t *testing.T) {
|
||||
ub := &Account{
|
||||
Id: "TEST_UB",
|
||||
BalanceMap: map[string]BalanceChain{utils.MONETARY: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 100, ExpirationDate: time.Date(2015, time.November, 9, 9, 48, 0, 0, time.UTC)}}, utils.VOICE: BalanceChain{&Balance{Value: 10, Weight: 20, DestinationIds: utils.StringMap{"NAT": true}, Directions: utils.StringMap{utils.OUT: true}}, &Balance{Weight: 10, DestinationIds: utils.StringMap{"RET": true}}}},
|
||||
ActionTriggers: ActionTriggers{
|
||||
&ActionTrigger{Id: "check expired balances", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: utils.TRIGGER_EXP_BALANCE, ActionsId: "TEST_ACTIONS"},
|
||||
},
|
||||
}
|
||||
ub.executeActionTriggers(nil)
|
||||
if ub.BalanceMap[utils.MONETARY][0].IsExpired() ||
|
||||
ub.BalanceMap[utils.MONETARY][0].GetValue() != 10 || // expired was cleaned
|
||||
ub.BalanceMap[utils.VOICE][0].GetValue() != 20 ||
|
||||
ub.ActionTriggers[0].Executed != true {
|
||||
t.Log(ub.BalanceMap[utils.MONETARY][0].IsExpired())
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY][0].GetValue(), ub.BalanceMap[utils.VOICE][0].GetValue(), len(ub.BalanceMap[utils.MONETARY]))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanExpired(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user