diff --git a/engine/actions_test.go b/engine/actions_test.go index 573854031..ea7e07c9d 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -978,6 +978,29 @@ func TestTopupAction(t *testing.T) { } } +func TestTopupActionLoaded(t *testing.T) { + initialUb, _ := accountingStorage.GetAccount("*out:vdf:minitsboy") + a := &Action{ + ActionType: "*topup", + BalanceType: CREDIT, + Direction: OUTBOUND, + Balance: &Balance{Value: 25, DestinationId: "RET", Weight: 20}, + } + + at := &ActionTiming{ + AccountIds: []string{"*out:vdf:minitsboy"}, + actions: Actions{a}, + } + + at.Execute() + afterUb, _ := accountingStorage.GetAccount("*out:vdf:minitsboy") + initialValue := initialUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() + afterValue := afterUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() + if initialValue != 100 || afterValue != 125 { + t.Error("Bad topup before and after: ", initialValue, afterValue) + } +} + /********************************** Benchmarks ********************************/ func BenchmarkUUID(b *testing.B) { diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 63160064b..5b0fd0b00 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -62,11 +62,25 @@ func populateDB() { &Balance{Value: 100, DestinationId: "RET", Weight: 20}, }}, } + // this is added to test if csv load tests account will not overwrite balances + minitsboy := &Account{ + Id: "*out:vdf:minitsboy", + BalanceMap: map[string]BalanceChain{ + MINUTES + OUTBOUND: BalanceChain{ + &Balance{Value: 20, DestinationId: "NAT", Weight: 10, RateSubject: "rif"}, + &Balance{Value: 100, DestinationId: "RET", Weight: 20}, + }, + CREDIT + OUTBOUND: BalanceChain{ + &Balance{Value: 100, Weight: 10}, + }, + }, + } if accountingStorage != nil { accountingStorage.SetActions("TEST_ACTIONS", ats) accountingStorage.SetActions("TEST_ACTIONS_ORDER", ats1) accountingStorage.SetAccount(broker) accountingStorage.SetAccount(minu) + accountingStorage.SetAccount(minitsboy) } else { log.Fatal("Could not connect to db!") } diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 7802d7a25..8cee2496e 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -754,6 +754,16 @@ func TestLoadAccountActions(t *testing.T) { if !reflect.DeepEqual(aa, expected) { t.Error("Error loading account action: ", aa) } + // test that it does not overwrite balances + existing, err := accountingStorage.GetAccount(aa.Id) + if err != nil || len(existing.BalanceMap) != 2 { + t.Errorf("The account was not set before load: %+v", existing) + } + accountingStorage.SetAccount(aa) + existing, err = accountingStorage.GetAccount(aa.Id) + if err != nil || len(existing.BalanceMap) != 2 { + t.Errorf("The set account altered the balances: %+v", existing) + } } func TestLoadAliases(t *testing.T) {