mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
corrected trigger tests
This commit is contained in:
@@ -114,14 +114,16 @@ func resetCountersAction(ub *UserBalance, a *Action) (err error) {
|
||||
|
||||
func genericMakeNegative(a *Action) {
|
||||
a.Units = -a.Units
|
||||
a.MinuteBucket.Seconds = -a.MinuteBucket.Seconds
|
||||
if a.MinuteBucket != nil {
|
||||
a.MinuteBucket.Seconds = -a.MinuteBucket.Seconds
|
||||
}
|
||||
}
|
||||
|
||||
func genericDebit(ub *UserBalance, a *Action) (err error) {
|
||||
if ub.BalanceMap == nil {
|
||||
ub.BalanceMap = make(map[string]float64)
|
||||
}
|
||||
switch a.ActionType {
|
||||
switch a.BalanceId {
|
||||
case CREDIT:
|
||||
ub.debitMoneyBalance(a.Units)
|
||||
case SMS:
|
||||
|
||||
@@ -24,6 +24,25 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
storageGetter, _ = NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
SetStorageGetter(storageGetter)
|
||||
populateTestActions()
|
||||
}
|
||||
|
||||
func populateTestActions() {
|
||||
/*ats := []*Action{
|
||||
&Action{ActionType: "TOPUP", BalanceId: CREDIT, Units: 10},
|
||||
&Action{ActionType: "TOPUP", BalanceId: MINUTES, MinuteBucket: &MinuteBucket{Seconds: 10, DestinationId: "NAT"}},
|
||||
}
|
||||
storageGetter.SetActions("TEST_ACTIONS", ats)
|
||||
ats1 := []*Action{
|
||||
&Action{ActionType: "TOPUP", BalanceId: CREDIT, Units: 10, Weight: 20},
|
||||
&Action{ActionType: "RESET_PREPAID", Weight: 10},
|
||||
}
|
||||
storageGetter.SetActions("TEST_ACTIONS_ORDER", ats1)*/
|
||||
}
|
||||
|
||||
func TestActionTimingStoreRestore(t *testing.T) {
|
||||
i := &Interval{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
|
||||
@@ -104,7 +104,6 @@ Debits some amount of user's money credit. Returns the remaining credit in user'
|
||||
*/
|
||||
func (ub *UserBalance) debitMoneyBalance(amount float64) float64 {
|
||||
ub.BalanceMap[CREDIT] -= amount
|
||||
|
||||
return ub.BalanceMap[CREDIT]
|
||||
}
|
||||
|
||||
@@ -113,7 +112,6 @@ func (ub *UserBalance) debitMinuteBucket(newMb *MinuteBucket) error {
|
||||
if newMb == nil {
|
||||
return errors.New("Nil minute bucket!")
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, mb := range ub.MinuteBuckets {
|
||||
if mb.Equal(newMb) {
|
||||
@@ -123,7 +121,7 @@ func (ub *UserBalance) debitMinuteBucket(newMb *MinuteBucket) error {
|
||||
}
|
||||
}
|
||||
// if it is not found and the Seconds are negative (topup)
|
||||
// then we adde it to the list
|
||||
// then we add it to the list
|
||||
if !found && newMb.Seconds <= 0 {
|
||||
newMb.Seconds = -newMb.Seconds
|
||||
ub.MinuteBuckets = append(ub.MinuteBuckets, newMb)
|
||||
@@ -133,9 +131,12 @@ func (ub *UserBalance) debitMinuteBucket(newMb *MinuteBucket) error {
|
||||
|
||||
// Adds the minutes from the received minute bucket to an existing bucket if the destination
|
||||
// is the same or ads the minute bucket to the list if none matches.
|
||||
func (ub *UserBalance) addMinuteBucket(newMb *MinuteBucket) {
|
||||
func (ub *UserBalance) addMinuteBucket(newMb *MinuteBucket) error {
|
||||
if newMb == nil {
|
||||
return errors.New("Nil minute bucket!")
|
||||
}
|
||||
newMb.Seconds = -newMb.Seconds
|
||||
ub.debitMinuteBucket(newMb)
|
||||
return ub.debitMinuteBucket(newMb)
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -31,13 +31,13 @@ var (
|
||||
func init() {
|
||||
storageGetter, _ = NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
SetStorageGetter(storageGetter)
|
||||
populateTestActions()
|
||||
populateTestActionsForTriggers()
|
||||
}
|
||||
|
||||
func populateTestActions() {
|
||||
func populateTestActionsForTriggers() {
|
||||
ats := []*Action{
|
||||
&Action{ActionType: "TOPUP", BalanceId: CREDIT, Units: 10},
|
||||
&Action{ActionType: "TOPUP", BalanceId: MINUTES, MinuteBucket: &MinuteBucket{Seconds: 10, DestinationId: "NAT"}},
|
||||
&Action{ActionType: "TOPUP", BalanceId: MINUTES, MinuteBucket: &MinuteBucket{Weight: 20, Price: 1, Seconds: 10, DestinationId: "NAT"}},
|
||||
}
|
||||
storageGetter.SetActions("TEST_ACTIONS", ats)
|
||||
ats1 := []*Action{
|
||||
|
||||
Reference in New Issue
Block a user