From c2c6815a71d93bc613361a6d312000b61927dba0 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 3 Nov 2015 19:43:18 +0200 Subject: [PATCH] reset trigger by id test --- engine/units_counter_test.go | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/engine/units_counter_test.go b/engine/units_counter_test.go index a8ec56785..a54153354 100644 --- a/engine/units_counter_test.go +++ b/engine/units_counter_test.go @@ -245,3 +245,85 @@ func TestUnitCountersCountAllVoiceDestinationEvent(t *testing.T) { t.Errorf("Error adding unit counters: %v", len(a.UnitCounters)) } } + +func TestUnitCountersResetCounterById(t *testing.T) { + a := &Account{ + ActionTriggers: ActionTriggers{ + &ActionTrigger{ + Id: "TestTR1", + ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + BalanceType: utils.MONETARY, + BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), + BalanceWeight: 10, + }, + &ActionTrigger{ + Id: "TestTR11", + ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + BalanceType: utils.MONETARY, + BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), + BalanceWeight: 10, + }, + &ActionTrigger{ + Id: "TestTR2", + ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + BalanceType: utils.VOICE, + BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), + BalanceWeight: 10, + }, + &ActionTrigger{ + Id: "TestTR3", + ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + BalanceType: utils.VOICE, + BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), + BalanceWeight: 10, + }, + &ActionTrigger{ + Id: "TestTR4", + ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + BalanceType: utils.SMS, + BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), + BalanceWeight: 10, + }, + &ActionTrigger{ + Id: "TestTR5", + ThresholdType: TRIGGER_MAX_BALANCE, + BalanceType: utils.SMS, + BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), + BalanceWeight: 10, + }, + }, + } + a.InitCounters() + a.UnitCounters.addUnits(10, utils.MONETARY, &CallCost{}, nil) + + if len(a.UnitCounters) != 4 || + len(a.UnitCounters[0].Balances) != 2 || + a.UnitCounters[0].Balances[0].Value != 10 || + a.UnitCounters[0].Balances[1].Value != 10 { + for _, uc := range a.UnitCounters { + t.Logf("UC: %+v", uc) + for _, b := range uc.Balances { + t.Logf("B: %+v", b) + } + } + t.Errorf("Error Initializing adding unit counters: %v", len(a.UnitCounters)) + } + a.UnitCounters.resetCounters(&Action{ + BalanceType: utils.MONETARY, + Balance: &Balance{ + Id: "TestTR11", + }, + }) + if len(a.UnitCounters) != 4 || + len(a.UnitCounters[0].Balances) != 2 || + a.UnitCounters[0].Balances[0].Value != 10 || + a.UnitCounters[0].Balances[1].Value != 0 { + for _, uc := range a.UnitCounters { + t.Logf("UC: %+v", uc) + for _, b := range uc.Balances { + t.Logf("B: %+v", b) + } + } + t.Errorf("Error Initializing adding unit counters: %v", len(a.UnitCounters)) + } +}