added test for remove account

fixes #116
This commit is contained in:
Radu Ioan Fericean
2015-07-13 21:08:04 +03:00
parent dc821c59eb
commit b215382e5b
3 changed files with 25 additions and 4 deletions

View File

@@ -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

View File

@@ -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},

View File

@@ -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"]