diff --git a/engine/action_plan.go b/engine/action_plan.go index d82d91c47..1cf386e99 100644 --- a/engine/action_plan.go +++ b/engine/action_plan.go @@ -245,7 +245,7 @@ func (at *ActionPlan) Execute() (err error) { return } for _, a := range aac { - if expDate, parseErr := utils.ParseDate(a.ExpirationString); a.Balance.ExpirationDate.IsZero() && parseErr == nil && !expDate.IsZero() { + if expDate, parseErr := utils.ParseDate(a.ExpirationString); (a.Balance == nil || a.Balance.ExpirationDate.IsZero()) && parseErr == nil && !expDate.IsZero() { a.Balance.ExpirationDate = expDate } // handle remove action diff --git a/engine/actions_test.go b/engine/actions_test.go index ff14c1709..c967cb1fe 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -1064,10 +1064,30 @@ func TestActionMakeNegative(t *testing.T) { } } +func TestRemoveAction(t *testing.T) { + if _, err := accountingStorage.GetAccount("*out:cgrates.org:remo"); err != nil { + t.Errorf("account to be removed not found: %v", err) + } + a := &Action{ + ActionType: REMOVE_ACCOUNT, + } + + at := &ActionPlan{ + AccountIds: []string{"*out:cgrates.org:remo"}, + actions: Actions{a}, + } + + at.Execute() + afterUb, err := accountingStorage.GetAccount("*out:cgrates.org:remo") + if err != utils.ErrNotFound || afterUb != nil { + t.Error("error removing account: ", err) + } +} + func TestTopupAction(t *testing.T) { initialUb, _ := accountingStorage.GetAccount("*out:vdf:minu") a := &Action{ - ActionType: "*topup", + ActionType: TOPUP, BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 25, DestinationIds: "RET", Weight: 20}, @@ -1090,7 +1110,7 @@ func TestTopupAction(t *testing.T) { func TestTopupActionLoaded(t *testing.T) { initialUb, _ := accountingStorage.GetAccount("*out:vdf:minitsboy") a := &Action{ - ActionType: "*topup", + ActionType: TOPUP, BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 25, DestinationIds: "RET", Weight: 20}, diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 919104bfa..7206bde5a 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -188,6 +188,7 @@ CDRST2_WARN_ACD,,*min_acd,3,true,0,,,,,,,,,,,5,CDRST_WARN_HTTP,10 accountActions = ` vdf,minitsboy;a1;a2,*out,MORE_MINUTES,STANDARD_TRIGGER cgrates.org,12345,*out,TOPUP10_AT,STANDARD_TRIGGERS +cgrates.org,remo,*out,TOPUP10_AT, vdf,empty0,*out,TOPUP_SHARED0_AT, vdf,empty10,*out,TOPUP_SHARED10_AT, vdf,emptyX,*out,TOPUP_EMPTY_AT, @@ -1002,7 +1003,7 @@ func TestLoadActionTriggers(t *testing.T) { } func TestLoadAccountActions(t *testing.T) { - if len(csvr.accountActions) != 7 { + if len(csvr.accountActions) != 8 { t.Error("Failed to load account actions: ", len(csvr.accountActions)) } aa := csvr.accountActions["*out:vdf:minitsboy"]