mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
@@ -94,6 +94,9 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
|
||||
return errors.New("nil action")
|
||||
}
|
||||
bClone := a.Balance.Clone()
|
||||
if bClone == nil {
|
||||
return errors.New("nil balance")
|
||||
}
|
||||
|
||||
if ub.BalanceMap == nil {
|
||||
ub.BalanceMap = make(map[string]BalanceChain, 1)
|
||||
|
||||
@@ -377,8 +377,7 @@ func genericDebit(ub *Account, a *Action, reset bool) (err error) {
|
||||
if ub.BalanceMap == nil {
|
||||
ub.BalanceMap = make(map[string]BalanceChain)
|
||||
}
|
||||
ub.debitBalanceAction(a, reset)
|
||||
return
|
||||
return ub.debitBalanceAction(a, reset)
|
||||
}
|
||||
|
||||
func enableUserAction(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) (err error) {
|
||||
|
||||
@@ -300,7 +300,6 @@ func (at *ActionPlan) Execute() (err error) {
|
||||
// TODO: maybe we should break here as the account is gone
|
||||
// will leave continue for now as the next action can create another acount
|
||||
}
|
||||
|
||||
actionFunction, exists := getActionFunc(a.ActionType)
|
||||
if !exists {
|
||||
// do not allow the action plan to be rescheduled
|
||||
@@ -309,7 +308,6 @@ func (at *ActionPlan) Execute() (err error) {
|
||||
transactionFailed = true
|
||||
break
|
||||
}
|
||||
|
||||
if err := actionFunction(ub, nil, a, aac); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("Error executing action %s: %v!", a.ActionType, err))
|
||||
transactionFailed = true
|
||||
|
||||
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -418,13 +419,13 @@ func TestActionPlanFunctionNotAvailable(t *testing.T) {
|
||||
Balance: &Balance{Value: 1.1},
|
||||
}
|
||||
at := &ActionPlan{
|
||||
AccountIds: []string{"one", "two", "three"},
|
||||
AccountIds: []string{"cgrates.org:dy"},
|
||||
Timing: &RateInterval{},
|
||||
actions: []*Action{a},
|
||||
}
|
||||
err := at.Execute()
|
||||
if at.Timing != nil {
|
||||
t.Logf("Faild to detect wrong function type: %v", err)
|
||||
if err != nil {
|
||||
t.Errorf("Faild to detect wrong function type: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1274,6 +1275,84 @@ func TestActionSetDDestination(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTransactionFuncType(t *testing.T) {
|
||||
err := accountingStorage.SetAccount(&Account{
|
||||
Id: "cgrates.org:trans",
|
||||
BalanceMap: map[string]BalanceChain{
|
||||
utils.MONETARY: BalanceChain{&Balance{
|
||||
Value: 10,
|
||||
}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("Error setting account: ", err)
|
||||
}
|
||||
at := &ActionPlan{
|
||||
AccountIds: []string{"cgrates.org:trans"},
|
||||
Timing: &RateInterval{},
|
||||
actions: []*Action{
|
||||
&Action{
|
||||
ActionType: TOPUP,
|
||||
BalanceType: utils.MONETARY,
|
||||
Balance: &Balance{Value: 1.1},
|
||||
},
|
||||
&Action{
|
||||
ActionType: "VALID_FUNCTION_TYPE",
|
||||
BalanceType: "test",
|
||||
Balance: &Balance{Value: 1.1},
|
||||
},
|
||||
},
|
||||
}
|
||||
log.Print("=========")
|
||||
err = at.Execute()
|
||||
log.Print("=========")
|
||||
acc, err := accountingStorage.GetAccount("cgrates.org:trans")
|
||||
if err != nil || acc == nil {
|
||||
t.Error("Error getting account: ", acc, err)
|
||||
}
|
||||
if acc.BalanceMap[utils.MONETARY][0].Value != 10 {
|
||||
t.Errorf("Transaction didn't work: %v", acc.BalanceMap[utils.MONETARY][0].Value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTransactionBalanceType(t *testing.T) {
|
||||
err := accountingStorage.SetAccount(&Account{
|
||||
Id: "cgrates.org:trans",
|
||||
BalanceMap: map[string]BalanceChain{
|
||||
utils.MONETARY: BalanceChain{&Balance{
|
||||
Value: 10,
|
||||
}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("Error setting account: ", err)
|
||||
}
|
||||
at := &ActionPlan{
|
||||
AccountIds: []string{"cgrates.org:trans"},
|
||||
Timing: &RateInterval{},
|
||||
actions: []*Action{
|
||||
&Action{
|
||||
ActionType: TOPUP,
|
||||
BalanceType: utils.MONETARY,
|
||||
Balance: &Balance{Value: 1.1},
|
||||
},
|
||||
&Action{
|
||||
ActionType: TOPUP,
|
||||
BalanceType: "test",
|
||||
Balance: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
err = at.Execute()
|
||||
acc, err := accountingStorage.GetAccount("cgrates.org:trans")
|
||||
if err != nil || acc == nil {
|
||||
t.Error("Error getting account: ", acc, err)
|
||||
}
|
||||
if acc.BalanceMap[utils.MONETARY][0].Value != 10 {
|
||||
t.Errorf("Transaction didn't work: %v", acc.BalanceMap[utils.MONETARY][0].Value)
|
||||
}
|
||||
}
|
||||
|
||||
/**************** Benchmarks ********************************/
|
||||
|
||||
func BenchmarkUUID(b *testing.B) {
|
||||
|
||||
@@ -217,12 +217,13 @@ func (b *Balance) MatchActionTrigger(at *ActionTrigger) bool {
|
||||
}
|
||||
|
||||
func (b *Balance) Clone() *Balance {
|
||||
return &Balance{
|
||||
if b == nil {
|
||||
return nil
|
||||
}
|
||||
n := &Balance{
|
||||
Uuid: b.Uuid,
|
||||
Id: b.Id,
|
||||
Value: b.Value, // this value is in seconds
|
||||
DestinationIds: b.DestinationIds.Clone(),
|
||||
Directions: b.Directions.Clone(),
|
||||
ExpirationDate: b.ExpirationDate,
|
||||
Weight: b.Weight,
|
||||
RatingSubject: b.RatingSubject,
|
||||
@@ -233,6 +234,13 @@ func (b *Balance) Clone() *Balance {
|
||||
Disabled: b.Disabled,
|
||||
dirty: b.dirty,
|
||||
}
|
||||
if b.DestinationIds != nil {
|
||||
n.DestinationIds = b.DestinationIds.Clone()
|
||||
}
|
||||
if b.Directions != nil {
|
||||
n.Directions = b.Directions.Clone()
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (b *Balance) getMatchingPrefixAndDestId(dest string) (prefix, destId string) {
|
||||
|
||||
Reference in New Issue
Block a user