Active commented tests in accounts

This commit is contained in:
TeoV
2021-02-10 14:26:27 +02:00
committed by Dan Christian Bogos
parent 971bd77198
commit b62039f57f
3 changed files with 31 additions and 22 deletions

View File

@@ -68,7 +68,6 @@ func (aB *abstractBalance) debitUsage(usage *utils.Decimal,
aB.blnCfg.Units.Big = utils.SubstractBig(aB.blnCfg.Units.Big, blncLmt.Big)
hasLmt = true
}
// unitFactor
var uF *utils.UnitFactor
if uF, err = unitFactor(aB.blnCfg.UnitFactors, aB.fltrS, cgrEv.Tenant, evNm); err != nil {
@@ -87,8 +86,8 @@ func (aB *abstractBalance) debitUsage(usage *utils.Decimal,
return
}
// balance smaller than usage, correct usage
if aB.blnCfg.Units.Compare(usage) == -1 {
// balance smaller than usage, correct usage if the balance has limit
if aB.blnCfg.Units.Compare(usage) == -1 && blncLmt != nil {
// decrease the usage to match the maximum increments
// will use special rounding to 0 since otherwise we go negative (ie: 0.05 as increment)
usage.Big = roundedUsageWithIncrements(aB.blnCfg.Units.Big, costIcrm.Increment.Big)

View File

@@ -229,8 +229,6 @@ func TestABCost0(t *testing.T) {
}
}
/*
TODO: discuss about this test try to debit only from abstract balance with cost 0
func TestABCost0WithoutConcrete(t *testing.T) {
// consume units only from abstract balance
aB := &abstractBalance{
@@ -257,7 +255,6 @@ func TestABCost0WithoutConcrete(t *testing.T) {
t.Errorf("Unexpected units in abstract balance: %s", aB.blnCfg.Units)
}
}
*/
func TestABCost0Exceed(t *testing.T) {
// consume more units that has an abstract balance
@@ -297,8 +294,33 @@ func TestABCost0Exceed(t *testing.T) {
}
}
/*
TODO: discuss about this test try to debit usage from an abstract balance with Units -1 and unlimited options
func TestABCost0ExceedWithoutConcrete(t *testing.T) {
// consume more units that has an abstract balance
aB := &abstractBalance{
blnCfg: &utils.Balance{
ID: "AB_COST_0",
Type: utils.MetaAbstract,
Units: utils.NewDecimal(int64(time.Duration(60*time.Second)), 0), // 1 Minute
CostIncrements: []*utils.CostIncrement{
{
Increment: utils.NewDecimal(int64(time.Duration(time.Second)), 0),
RecurrentFee: utils.NewDecimal(0, 0),
},
},
},
fltrS: new(engine.FilterS),
}
if ec, err := aB.debitUsage(utils.NewDecimal(int64(70*time.Second), 0),
new(utils.CGREvent)); err != nil {
t.Error(err)
} else if ec.Usage.Cmp(decimal.New(int64(60*time.Second), 0)) != 0 {
t.Errorf("Unexpected debited units: %s", ec.Usage)
} else if aB.blnCfg.Units.Compare(utils.NewDecimal(0, 0)) != 0 {
t.Errorf("Unexpected units in abstract balance: %s", aB.blnCfg.Units)
}
}
func TestABCost0WithUnlimited(t *testing.T) {
// consume more units that has an abstract balance
aB := &abstractBalance{
@@ -316,15 +338,6 @@ func TestABCost0WithUnlimited(t *testing.T) {
},
},
},
cncrtBlncs: []*concreteBalance{
{
blnCfg: &utils.Balance{
ID: "CB",
Type: utils.MetaConcrete,
Units: utils.NewDecimal(10, 0),
},
},
},
fltrS: new(engine.FilterS),
}
@@ -335,8 +348,5 @@ func TestABCost0WithUnlimited(t *testing.T) {
t.Errorf("Unexpected debited units: %s", ec.Usage)
} else if aB.blnCfg.Units.Compare(utils.NewDecimal(-int64(time.Duration(20*time.Second)), 0)) != 0 {
t.Errorf("Unexpected units in abstract balance: %s", aB.blnCfg.Units)
} else if aB.cncrtBlncs[0].blnCfg.Units.Compare(utils.NewDecimal(10, 0)) != 0 {
t.Errorf("Unexpected units in concrete balance: %s", aB.cncrtBlncs[0].blnCfg.Units)
}
}
*/

View File

@@ -410,9 +410,9 @@ func TestCBDebitWithUnitFactorWithFiltersWithLimit(t *testing.T) {
if dbted, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
"cgrates.org", mp); err != nil {
t.Error(err)
} else if dbted.Compare(utils.NewDecimal(3, 0)) != 0 {
} else if dbted.Compare(utils.NewDecimal(2, 0)) != 0 {
t.Errorf("debited: %s", dbted)
} else if cb.blnCfg.Units.Cmp(decimal.New(200, 0)) != 0 {
} else if cb.blnCfg.Units.Cmp(decimal.New(300, 0)) != 0 {
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
}
}