rounding unit tests

This commit is contained in:
Radu Ioan Fericean
2016-03-04 16:10:29 +02:00
parent f71e14d8d4
commit ce8f7bf927
3 changed files with 39 additions and 8 deletions

View File

@@ -777,7 +777,6 @@ func (cd *CallDescriptor) RefundIncrements() error {
for _, increment := range cd.Increments {
accMap[increment.BalanceInfo.AccountId] = true
}
accountIDs := accMap.Slice()
// start increment refunding loop
_, err := Guardian.Guard(func() (interface{}, error) {
accountsCache := make(map[string]*Account)
@@ -816,7 +815,7 @@ func (cd *CallDescriptor) RefundIncrements() error {
}
}
return 0, nil
}, 0, accountIDs...)
}, 0, accMap.Slice()...)
return err
}
@@ -827,7 +826,6 @@ func (cd *CallDescriptor) RefundRounding() error {
for _, inc := range cd.Increments {
accMap[inc.BalanceInfo.AccountId] = true
}
accountIDs := accMap.Slice()
// start increment refunding loop
_, err := Guardian.Guard(func() (interface{}, error) {
accountsCache := make(map[string]*Account)
@@ -851,14 +849,12 @@ func (cd *CallDescriptor) RefundRounding() error {
if balance = account.BalanceMap[utils.MONETARY].GetBalance(increment.BalanceInfo.MoneyBalanceUuid); balance == nil {
return 0, nil
}
//log.Print("BEFORE: ", balance.GetValue(), increment.Cost)
balance.AddValue(-increment.Cost)
//log.Print("AFTER: ", balance.GetValue(), increment.Cost)
account.countUnits(increment.Cost, utils.MONETARY, cc, balance)
}
}
return 0, nil
}, 0, accountIDs...)
}, 0, accMap.Slice()...)
return err
}

View File

@@ -745,7 +745,7 @@ func TestMaxDebitUnknowDest(t *testing.T) {
}
}
func TestGetCostMaxDebitRoundingIssue(t *testing.T) {
func TestMaxDebitRoundingIssue(t *testing.T) {
ap, _ := ratingStorage.GetActionPlan("TOPUP10_AT", false)
for _, at := range ap.ActionTimings {
at.accountIDs = ap.AccountIDs
@@ -780,6 +780,41 @@ func TestGetCostMaxDebitRoundingIssue(t *testing.T) {
}
}
func TestDebitRoundingRefund(t *testing.T) {
ap, _ := ratingStorage.GetActionPlan("TOPUP10_AT", false)
for _, at := range ap.ActionTimings {
at.accountIDs = ap.AccountIDs
at.Execute()
}
cd := &CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "dy",
Account: "dy",
Destination: "0723123113",
TimeStart: time.Date(2016, 3, 4, 13, 50, 00, 0, time.UTC),
TimeEnd: time.Date(2016, 3, 4, 13, 53, 00, 0, time.UTC),
MaxCostSoFar: 0,
PerformRounding: true,
}
acc, err := accountingStorage.GetAccount("cgrates.org:dy")
if err != nil || acc.BalanceMap[utils.MONETARY][0].Value != 1 {
t.Errorf("Error getting account: %+v (%v)", utils.ToIJSON(acc), err)
}
cc, err := cd.Debit()
expected := 0.3
if cc.Cost != expected || err != nil {
t.Log(utils.ToIJSON(cc))
t.Errorf("Expected %v was %+v (%v)", expected, cc, err)
}
acc, err = accountingStorage.GetAccount("cgrates.org:dy")
if err != nil || acc.BalanceMap[utils.MONETARY][0].Value != 1-expected {
t.Errorf("Error getting account: %+v (%v)", utils.ToIJSON(acc), err)
}
}
func TestMaxSessionTimeWithMaxCostFree(t *testing.T) {
ap, _ := ratingStorage.GetActionPlan("TOPUP10_AT", false)
for _, at := range ap.ActionTimings {

View File

@@ -33,13 +33,13 @@ A unit in which a call will be split that has a specific price related interval
type TimeSpan struct {
TimeStart, TimeEnd time.Time
Cost float64
ratingInfo *RatingInfo
RateInterval *RateInterval
DurationIndex time.Duration // the call duration so far till TimeEnd
Increments Increments
RoundIncrements Increments
MatchedSubject, MatchedPrefix, MatchedDestId, RatingPlanId string
CompressFactor int
ratingInfo *RatingInfo
}
type Increment struct {