diff --git a/engine/account.go b/engine/account.go index 8a6eefb82..0e8d0505e 100644 --- a/engine/account.go +++ b/engine/account.go @@ -102,6 +102,7 @@ func (ub *Account) debitBalanceAction(a *Action) error { } if b.Equal(a.Balance) { b.Value -= a.Balance.Value + b.Value = utils.Round(b.Value, roundingDecimals, utils.ROUNDING_MIDDLE) found = true break } @@ -240,6 +241,7 @@ CONNECT_FEE: for _, b := range usefulMoneyBalances { if b.Value >= amount { b.Value -= amount + b.Value = utils.Round(b.Value, roundingDecimals, utils.ROUNDING_MIDDLE) // the conect fee is not refundable! if count { ub.countUnits(&Action{BalanceType: CREDIT, Direction: cc.Direction, Balance: &Balance{Value: amount, DestinationId: cc.Destination}}) @@ -378,9 +380,7 @@ func (ub *Account) refundIncrements(increments Increments, direction string, cou } } -/* -Debits some amount of user's specified balance. Returns the remaining credit in user's balance. -*/ +// Debits some amount of user's specified balance. Returns the remaining credit in user's balance. func (ub *Account) debitGenericBalance(balanceId string, direction string, amount float64, count bool) float64 { if count { ub.countUnits(&Action{BalanceType: balanceId, Direction: direction, Balance: &Balance{Value: amount}}) diff --git a/engine/account_test.go b/engine/account_test.go index db6bdccb9..88b79e836 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -1032,27 +1032,8 @@ func TestAccountRefund(t *testing.T) { } } -func TestTopupAction(t *testing.T) { - initialUb, _ := accountingStorage.GetAccount("*out:vdf:minu") - a := &Action{ - ActionType: "*topup", - BalanceType: CREDIT, - Direction: OUTBOUND, - Balance: &Balance{Value: 25, DestinationId: "RET", Weight: 20}, - } +func TestDebitShared(t *testing.T) { - at := &ActionTiming{ - AccountIds: []string{"*out:vdf:minu"}, - actions: Actions{a}, - } - - at.Execute() - afterUb, _ := accountingStorage.GetAccount("*out:vdf:minu") - initialValue := initialUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() - afterValue := afterUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() - if initialValue != 50 || afterValue != 75 { - t.Error("Bad topup before and after: ", initialValue, afterValue) - } } /*********************************** Benchmarks *******************************/ diff --git a/engine/actions_test.go b/engine/actions_test.go index 5321c06f2..08efcf8a3 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -955,8 +955,27 @@ func TestActionMakeNegative(t *testing.T) { } } -func TestMinBalanceTriggerSimple(t *testing.T) { - //ub := &Account{} +func TestTopupAction(t *testing.T) { + initialUb, _ := accountingStorage.GetAccount("*out:vdf:minu") + a := &Action{ + ActionType: "*topup", + BalanceType: CREDIT, + Direction: OUTBOUND, + Balance: &Balance{Value: 25, DestinationId: "RET", Weight: 20}, + } + + at := &ActionTiming{ + AccountIds: []string{"*out:vdf:minu"}, + actions: Actions{a}, + } + + at.Execute() + afterUb, _ := accountingStorage.GetAccount("*out:vdf:minu") + initialValue := initialUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() + afterValue := afterUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() + if initialValue != 50 || afterValue != 75 { + t.Error("Bad topup before and after: ", initialValue, afterValue) + } } /********************************** Benchmarks ********************************/ diff --git a/engine/calldesc.go b/engine/calldesc.go index 853304667..ff307502b 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -436,7 +436,7 @@ If the user has postpayed plan it returns -1. */ func (origCd *CallDescriptor) GetMaxSessionDuration() (time.Duration, error) { cd := origCd.Clone() - if cd.CallDuration == 0 { + if cd.CallDuration < cd.TimeEnd.Sub(cd.TimeStart) { cd.CallDuration = cd.TimeEnd.Sub(cd.TimeStart) } //Logger.Debug(fmt.Sprintf("MAX SESSION cd: %+v", cd))