mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Fixed unit tests for debitConcretes
This commit is contained in:
committed by
Dan Christian Bogos
parent
af87eaa5ae
commit
8566f8aff2
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/rpcclient"
|
||||
@@ -30,7 +31,6 @@ import (
|
||||
"github.com/ericlagergren/decimal"
|
||||
)
|
||||
|
||||
/*
|
||||
func TestCBDebitUnits(t *testing.T) {
|
||||
// with limit and unit factor
|
||||
cb := &concreteBalance{
|
||||
@@ -49,14 +49,20 @@ func TestCBDebitUnits(t *testing.T) {
|
||||
},
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
}
|
||||
unitFct := &utils.UnitFactor{
|
||||
Factor: utils.NewDecimal(100, 0),
|
||||
}
|
||||
toDebit := utils.NewDecimal(6, 0)
|
||||
if dbted, uFctr, err := cb.debitUnits(toDebit,
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(toDebit.Big,
|
||||
cgrEvent); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(cb.blnCfg.UnitFactors[0], uFctr) {
|
||||
t.Errorf("received unit factor: %+v", uFctr)
|
||||
} else if dbted.Compare(toDebit) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if !reflect.DeepEqual(cb.blnCfg.UnitFactors[0], unitFct) {
|
||||
t.Errorf("received unit factor: %+v", unitFct)
|
||||
} else if evChrgr.Usage.Compare(toDebit) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(-100, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
@@ -74,11 +80,11 @@ func TestCBDebitUnits(t *testing.T) {
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
toDebit = utils.NewDecimal(25, 1) //2.5
|
||||
if dbted, _, err := cb.debitUnits(toDebit,
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(toDebit.Big,
|
||||
cgrEvent); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Cmp(decimal.New(225, 2)) != 0 { // 2.25 debited
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Cmp(decimal.New(225, 2)) != 0 { // 2.25 debited
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(-1, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
@@ -96,11 +102,11 @@ func TestCBDebitUnits(t *testing.T) {
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
toDebit = utils.NewDecimal(25, 1) // 2.5
|
||||
if dbted, _, err := cb.debitUnits(toDebit,
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(toDebit.Big,
|
||||
cgrEvent); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Cmp(decimal.New(25, 1)) != 0 { // debit more than available since we have unlimited
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Cmp(decimal.New(25, 1)) != 0 { // debit more than available since we have unlimited
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(-125, 2)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
@@ -118,18 +124,16 @@ func TestCBDebitUnits(t *testing.T) {
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
toDebit = utils.NewDecimal(25, 1) //2.5
|
||||
if dbted, _, err := cb.debitUnits(toDebit,
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(toDebit.Big,
|
||||
cgrEvent); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Cmp(decimal.New(75, 2)) != 0 { // limit is 0.5
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Cmp(decimal.New(75, 2)) != 0 { // limit is 0.5
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(5, 1)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBSimpleDebit(t *testing.T) {
|
||||
// debit 10 units from a concrete balance with 500 units
|
||||
cb := &concreteBalance{
|
||||
@@ -141,17 +145,16 @@ func TestCBSimpleDebit(t *testing.T) {
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
toDebit := utils.NewDecimal(10, 0)
|
||||
if dbted, _, err := cb.debitUnits(toDebit,
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(toDebit.Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(toDebit) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(toDebit) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(490, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitExceed(t *testing.T) {
|
||||
// debit 510 units from a concrete balance with 500 units
|
||||
cb := &concreteBalance{
|
||||
@@ -162,17 +165,16 @@ func TestCBDebitExceed(t *testing.T) {
|
||||
},
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(510, 0),
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(510, 0).Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(500, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(500, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(0, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitUnlimited(t *testing.T) {
|
||||
// debit 510 units from an unlimited concrete balance with 100 units
|
||||
cb := &concreteBalance{
|
||||
@@ -186,17 +188,16 @@ func TestCBDebitUnlimited(t *testing.T) {
|
||||
},
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(510, 0),
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(510, 0).Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(510, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(510, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(-410, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitLimit(t *testing.T) {
|
||||
// debit 190 units from a concrete balance with 500 units and limit of 300
|
||||
cb := &concreteBalance{
|
||||
@@ -211,17 +212,16 @@ func TestCBDebitLimit(t *testing.T) {
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
toDebit := utils.NewDecimal(190, 0)
|
||||
if dbted, _, err := cb.debitUnits(toDebit,
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(toDebit.Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(toDebit) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(toDebit) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(310, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitLimitExceed(t *testing.T) {
|
||||
// debit 210 units from a concrete balance with 500 units and limit of 300
|
||||
cb := &concreteBalance{
|
||||
@@ -235,17 +235,16 @@ func TestCBDebitLimitExceed(t *testing.T) {
|
||||
},
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(210, 0),
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(210, 0).Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(200, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(200, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(300, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitLimitExceed2(t *testing.T) {
|
||||
// debit 510 units from a concrete balance with 500 units but because of limit it will debit only 200
|
||||
cb := &concreteBalance{
|
||||
@@ -259,17 +258,16 @@ func TestCBDebitLimitExceed2(t *testing.T) {
|
||||
},
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(510, 0),
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(510, 0).Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(200, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(200, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(300, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithUnitFactor(t *testing.T) {
|
||||
// debit 1 unit from balance but because of unit factor it will debit 100
|
||||
cb := &concreteBalance{
|
||||
@@ -286,17 +284,16 @@ func TestCBDebitWithUnitFactor(t *testing.T) {
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
toDebit := utils.NewDecimal(1, 0)
|
||||
if dbted, _, err := cb.debitUnits(toDebit,
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(toDebit.Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(toDebit) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(toDebit) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(400, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithUnitFactorWithLimit(t *testing.T) {
|
||||
// debit 3 units from balance but because of unit factor and limit it will debit 200
|
||||
cb := &concreteBalance{
|
||||
@@ -315,17 +312,16 @@ func TestCBDebitWithUnitFactorWithLimit(t *testing.T) {
|
||||
},
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(3, 0).Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(2, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(2, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(300, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithUnitFactorWithUnlimited(t *testing.T) {
|
||||
// debit 3 units from balance but because of unit factor and limit it will debit 200
|
||||
cb := &concreteBalance{
|
||||
@@ -344,17 +340,16 @@ func TestCBDebitWithUnitFactorWithUnlimited(t *testing.T) {
|
||||
},
|
||||
fltrS: new(engine.FilterS),
|
||||
}
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(7, 0),
|
||||
"cgrates.org", utils.MapStorage{}); err != nil {
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(7, 0).Big,
|
||||
new(utils.CGREvent)); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(7, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(7, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(-200, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithUnitFactorWithFilters1(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
@@ -378,27 +373,28 @@ func TestCBDebitWithUnitFactorWithFilters1(t *testing.T) {
|
||||
},
|
||||
fltrS: filterS,
|
||||
}
|
||||
mp := utils.MapStorage{}
|
||||
mp.Set([]string{utils.MetaReq}, map[string]interface{}{
|
||||
"NotMatching": "NotMatching",
|
||||
})
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(100, 0),
|
||||
"cgrates.org", mp); err != nil {
|
||||
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
"CustomField": "CustomValueee",
|
||||
},
|
||||
}
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(100, 0).Big,
|
||||
cgrEvent); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(100, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(100, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(400, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithUnitFactorWithFiltersWithLimit(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
|
||||
filterS := engine.NewFilterS(cfg, nil, dm)
|
||||
// debit 100 units from a balance ( the unit factor doesn't match )
|
||||
// debit 100 units from a balance ( the unit factor match)
|
||||
cb := &concreteBalance{
|
||||
blnCfg: &utils.Balance{
|
||||
ID: "CB",
|
||||
@@ -416,21 +412,21 @@ func TestCBDebitWithUnitFactorWithFiltersWithLimit(t *testing.T) {
|
||||
},
|
||||
fltrS: filterS,
|
||||
}
|
||||
mp := utils.MapStorage{}
|
||||
mp.Set([]string{utils.MetaReq}, map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
})
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
|
||||
"cgrates.org", mp); err != nil {
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
},
|
||||
}
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(3, 0).Big,
|
||||
cgrEvent); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(2, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(2, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(300, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithMultipleUnitFactor(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
@@ -455,27 +451,27 @@ func TestCBDebitWithMultipleUnitFactor(t *testing.T) {
|
||||
},
|
||||
fltrS: filterS,
|
||||
}
|
||||
mp := utils.MapStorage{}
|
||||
mp.Set([]string{utils.MetaReq}, map[string]interface{}{
|
||||
"CustomField2": "CustomValue2",
|
||||
})
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
|
||||
"cgrates.org", mp); err != nil {
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
"CustomField2": "CustomValue2",
|
||||
},
|
||||
}
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(3, 0).Big,
|
||||
cgrEvent); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(3, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(3, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(350, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithBalanceFilter(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
|
||||
filterS := engine.NewFilterS(cfg, nil, dm)
|
||||
// debit 100 units from a balance ( the unit factor doesn't match )
|
||||
// debit 3 units from a balance (the filter match)
|
||||
cb := &concreteBalance{
|
||||
blnCfg: &utils.Balance{
|
||||
ID: "CB",
|
||||
@@ -485,27 +481,27 @@ func TestCBDebitWithBalanceFilter(t *testing.T) {
|
||||
},
|
||||
fltrS: filterS,
|
||||
}
|
||||
mp := utils.MapStorage{}
|
||||
mp.Set([]string{utils.MetaReq}, map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
})
|
||||
if dbted, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
|
||||
"cgrates.org", mp); err != nil {
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
},
|
||||
}
|
||||
if evChrgr, err := cb.debitConcretes(utils.NewDecimal(3, 0).Big,
|
||||
cgrEvent); err != nil {
|
||||
t.Error(err)
|
||||
} else if dbted.Compare(utils.NewDecimal(3, 0)) != 0 {
|
||||
t.Errorf("debited: %s", dbted)
|
||||
} else if evChrgr.Usage.Compare(utils.NewDecimal(3, 0)) != 0 {
|
||||
t.Errorf("debited: %s", evChrgr.Usage)
|
||||
} else if cb.blnCfg.Units.Cmp(decimal.New(497, 0)) != 0 {
|
||||
t.Errorf("balance remaining: %s", cb.blnCfg.Units)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithBalanceFilterNotPassing(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
|
||||
filterS := engine.NewFilterS(cfg, nil, dm)
|
||||
// debit 100 units from a balance ( the unit factor doesn't match )
|
||||
// filter doesn't match )
|
||||
cb := &concreteBalance{
|
||||
blnCfg: &utils.Balance{
|
||||
ID: "CB",
|
||||
@@ -515,17 +511,17 @@ func TestCBDebitWithBalanceFilterNotPassing(t *testing.T) {
|
||||
},
|
||||
fltrS: filterS,
|
||||
}
|
||||
mp := utils.MapStorage{}
|
||||
mp.Set([]string{utils.MetaReq}, map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
})
|
||||
if _, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
|
||||
"cgrates.org", mp); err == nil || err != utils.ErrFilterNotPassingNoCaps {
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
},
|
||||
}
|
||||
if _, err := cb.debitConcretes(utils.NewDecimal(3, 0).Big,
|
||||
cgrEvent); err == nil || err != utils.ErrFilterNotPassingNoCaps {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithBalanceInvalidFilter(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
@@ -541,17 +537,17 @@ func TestCBDebitWithBalanceInvalidFilter(t *testing.T) {
|
||||
},
|
||||
fltrS: filterS,
|
||||
}
|
||||
mp := utils.MapStorage{}
|
||||
mp.Set([]string{utils.MetaReq}, map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
})
|
||||
if _, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
|
||||
"cgrates.org", mp); err == nil || err.Error() != "inline parse error for string: <*string>" {
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
},
|
||||
}
|
||||
if _, err := cb.debitConcretes(utils.NewDecimal(3, 0).Big,
|
||||
cgrEvent); err == nil || err.Error() != "inline parse error for string: <*string>" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithInvalidUnitFactorFilter(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
@@ -572,17 +568,17 @@ func TestCBDebitWithInvalidUnitFactorFilter(t *testing.T) {
|
||||
},
|
||||
fltrS: filterS,
|
||||
}
|
||||
mp := utils.MapStorage{}
|
||||
mp.Set([]string{utils.MetaReq}, map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
})
|
||||
if _, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
|
||||
"cgrates.org", mp); err == nil || err.Error() != "inline parse error for string: <*string>" {
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
},
|
||||
}
|
||||
if _, err := cb.debitConcretes(utils.NewDecimal(3, 0).Big,
|
||||
cgrEvent); err == nil || err.Error() != "inline parse error for string: <*string>" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
func TestCBDebitWithInvalidLimit(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
@@ -600,16 +596,17 @@ func TestCBDebitWithInvalidLimit(t *testing.T) {
|
||||
},
|
||||
fltrS: filterS,
|
||||
}
|
||||
mp := utils.MapStorage{}
|
||||
mp.Set([]string{utils.MetaReq}, map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
})
|
||||
if _, _, err := cb.debitUnits(utils.NewDecimal(3, 0),
|
||||
"cgrates.org", mp); err == nil || err.Error() != "unsupported *balanceLimit format" {
|
||||
cgrEvent := &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
"CustomField": "CustomValue",
|
||||
},
|
||||
}
|
||||
if _, err := cb.debitConcretes(utils.NewDecimal(3, 0).Big,
|
||||
cgrEvent); err == nil || err.Error() != "unsupported *balanceLimit format" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestCBSDebitUsage(t *testing.T) {
|
||||
// debit 10 units from a concrete balance with 500 units
|
||||
cb := &concreteBalance{
|
||||
|
||||
Reference in New Issue
Block a user