mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Replace RecurrentFee value from -1 to be nil
This commit is contained in:
committed by
Dan Christian Bogos
parent
69692ede55
commit
0ecfffeca1
@@ -95,7 +95,8 @@ func (aB *abstractBalance) debitAbstracts(usage *decimal.Big,
|
||||
// will use special rounding to 0 since otherwise we go negative (ie: 0.05 as increment)
|
||||
usage = roundUnitsWithIncrements(aB.blnCfg.Units.Big, costIcrm.Increment.Big)
|
||||
}
|
||||
if costIcrm.RecurrentFee.Cmp(decimal.New(0, 0)) == 0 &&
|
||||
if costIcrm.RecurrentFee != nil &&
|
||||
costIcrm.RecurrentFee.Cmp(decimal.New(0, 0)) == 0 &&
|
||||
(costIcrm.FixedFee == nil ||
|
||||
costIcrm.FixedFee.Cmp(decimal.New(0, 0)) == 0) {
|
||||
// cost 0, no need of concrete
|
||||
|
||||
@@ -668,9 +668,8 @@ func TestDebitUsageCostIncrementError(t *testing.T) {
|
||||
Type: utils.MetaAbstract,
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
{
|
||||
FilterIDs: []string{"INVALID_FILTER_FORMAT"},
|
||||
Increment: utils.NewDecimal(int64(1*time.Second), 0),
|
||||
RecurrentFee: utils.NewDecimal(2, 0),
|
||||
FilterIDs: []string{"INVALID_FILTER_FORMAT"},
|
||||
Increment: utils.NewDecimal(int64(1*time.Second), 0),
|
||||
},
|
||||
},
|
||||
Units: utils.NewDecimal(int64(60*time.Second), 0),
|
||||
@@ -691,7 +690,7 @@ func TestDebitUsageCostIncrementError(t *testing.T) {
|
||||
|
||||
//Will check the error by making the event charge
|
||||
//the cost is unknown, will use attributes to query from rates
|
||||
aB.blnCfg.CostIncrements = nil
|
||||
aB.blnCfg.CostIncrements[0].FilterIDs = []string{}
|
||||
aB.blnCfg.AttributeIDs = []string{"attr11"}
|
||||
expected := "NOT_CONNECTED: AttributeS"
|
||||
if _, err := aB.debitAbstracts(decimal.New(int64(20*time.Second), 0), cgrEv); err == nil ||
|
||||
|
||||
@@ -68,6 +68,7 @@ func TestShutDownCoverage(t *testing.T) {
|
||||
}
|
||||
|
||||
log.SetOutput(os.Stderr)
|
||||
utils.Logger.SetLogLevel(6)
|
||||
}
|
||||
|
||||
type dataDBMockErrorNotFound struct {
|
||||
@@ -448,6 +449,7 @@ func TestAccountsDebit(t *testing.T) {
|
||||
}
|
||||
|
||||
log.SetOutput(os.Stderr)
|
||||
utils.Logger.SetLogLevel(6)
|
||||
}
|
||||
|
||||
func TestV1AccountsForEvent(t *testing.T) {
|
||||
@@ -1334,8 +1336,8 @@ func TestV1DebitAbstractsEventCharges(t *testing.T) {
|
||||
Type: utils.MetaConcrete,
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
{
|
||||
Increment: utils.NewDecimal(int64(time.Second), 0),
|
||||
RecurrentFee: utils.NewDecimal(-1, 0)},
|
||||
Increment: utils.NewDecimal(int64(time.Second), 0),
|
||||
},
|
||||
},
|
||||
Units: utils.NewDecimal(125, 2), // 1.25
|
||||
},
|
||||
@@ -1375,8 +1377,8 @@ func TestV1DebitAbstractsEventCharges(t *testing.T) {
|
||||
},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
{
|
||||
Increment: utils.NewDecimal(int64(time.Second), 0),
|
||||
RecurrentFee: utils.NewDecimal(-1, 0)},
|
||||
Increment: utils.NewDecimal(int64(time.Second), 0),
|
||||
},
|
||||
},
|
||||
Units: utils.NewDecimal(1, 0), //0.8 covering the first balance 20s on it's own with RateS
|
||||
},
|
||||
@@ -1430,3 +1432,77 @@ func TestV1DebitAbstractsEventCharges(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestV1DebitAbstractsWithRecurrentFeeNegative(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltrS := engine.NewFilterS(cfg, nil, dm)
|
||||
accnts := NewAccountS(cfg, fltrS, nil, dm)
|
||||
|
||||
acnt := &utils.Account{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1DebitAbstractsWithRecurrentFeeNegative",
|
||||
Balances: map[string]*utils.Balance{
|
||||
"ab1": &utils.Balance{
|
||||
ID: "ab1",
|
||||
Type: utils.MetaAbstract,
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 30,
|
||||
},
|
||||
},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
{
|
||||
Increment: utils.NewDecimal(int64(time.Second), 0),
|
||||
RecurrentFee: utils.NewDecimal(1, 0)}, // 1.0 per minute
|
||||
},
|
||||
Units: utils.NewDecimal(int64(40*time.Second), 0),
|
||||
},
|
||||
"cb1": &utils.Balance{
|
||||
ID: "cb1",
|
||||
Type: utils.MetaConcrete,
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
{
|
||||
Increment: utils.NewDecimal(int64(time.Second), 0),
|
||||
RecurrentFee: utils.NewDecimal(-1, 0),
|
||||
},
|
||||
},
|
||||
Units: utils.NewDecimal(1, 0),
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dm.SetAccount(acnt, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
args := &utils.ArgsAccountsForEvent{
|
||||
CGREvent: &utils.CGREvent{
|
||||
ID: "TestV1DebitAbstractsWithRecurrentFeeNegative",
|
||||
Tenant: "cgrates.org",
|
||||
APIOpts: map[string]interface{}{
|
||||
utils.MetaUsage: "72h",
|
||||
},
|
||||
},
|
||||
}
|
||||
expEvCh := &utils.ExtEventCharges{
|
||||
Abstracts: utils.Float64Pointer(259200000000000),
|
||||
Concretes: utils.Float64Pointer(-259198),
|
||||
Accounting: map[string]*utils.ExtAccountCharge{},
|
||||
UnitFactors: map[string]*utils.ExtUnitFactor{},
|
||||
Rating: map[string]*utils.ExtRateSInterval{}}
|
||||
ev := &utils.ExtEventCharges{}
|
||||
if err := accnts.V1DebitAbstracts(args, ev); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(ev, expEvCh) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expEvCh), utils.ToJSON(ev))
|
||||
}
|
||||
|
||||
acnt.Balances["ab1"].Units = utils.NewDecimal(int64(39*time.Second), 0)
|
||||
acnt.Balances["cb1"].Units = utils.NewDecimal(259199, 0)
|
||||
if rcv, err := dm.GetAccount(acnt.Tenant, acnt.ID); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rcv, acnt) {
|
||||
t.Errorf("Expected %+v,received %+v", utils.ToJSON(acnt), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,8 +754,7 @@ func TestCBSDebitAbstractsCoverProcessAttributes(t *testing.T) { // coverage pur
|
||||
Units: utils.NewDecimal(500, 0), // 500 Units
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
{
|
||||
Increment: utils.NewDecimal(5, 0),
|
||||
RecurrentFee: utils.NewDecimal(-1, 0),
|
||||
Increment: utils.NewDecimal(5, 0),
|
||||
},
|
||||
},
|
||||
AttributeIDs: []string{"CustomAttr"},
|
||||
@@ -817,8 +816,7 @@ func TestCBSDebitAbstractsCoverProcessAttributes2(t *testing.T) { // coverage pu
|
||||
Units: utils.NewDecimal(500, 0), // 500 Units
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
{
|
||||
Increment: utils.NewDecimal(5, 0),
|
||||
RecurrentFee: utils.NewDecimal(-1, 0),
|
||||
Increment: utils.NewDecimal(5, 0),
|
||||
},
|
||||
},
|
||||
AttributeIDs: []string{"CustomAttr"},
|
||||
|
||||
@@ -151,9 +151,6 @@ func costIncrement(cfgCostIncrmts []*utils.CostIncrement,
|
||||
if costIcrm.Increment == nil {
|
||||
costIcrm.Increment = utils.NewDecimal(1, 0)
|
||||
}
|
||||
if costIcrm.RecurrentFee == nil {
|
||||
costIcrm.RecurrentFee = utils.NewDecimal(-1, 0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -227,7 +224,7 @@ func maxDebitAbstractsFromConcretes(aUnits *decimal.Big,
|
||||
attrSConns, attributeIDs, rateSConns, rpIDs []string,
|
||||
costIcrm *utils.CostIncrement) (ec *utils.EventCharges, err error) {
|
||||
// Init EventCharges
|
||||
calculateCost := costIcrm.RecurrentFee.Cmp(decimal.New(-1, 0)) == 0 && costIcrm.FixedFee == nil
|
||||
calculateCost := costIcrm.RecurrentFee == nil && costIcrm.FixedFee == nil
|
||||
//var attrIDs []string // will be populated if attributes are processed successfully
|
||||
// process AttributeS if needed
|
||||
if calculateCost && len(attributeIDs) != 0 { // cost unknown, apply AttributeS to query from RateS
|
||||
@@ -271,7 +268,7 @@ func maxDebitAbstractsFromConcretes(aUnits *decimal.Big,
|
||||
cUnits = costIcrm.FixedFee.Big
|
||||
}
|
||||
// RecurrentFee is configured, used it with increments
|
||||
if costIcrm.RecurrentFee.Big.Cmp(decimal.New(-1, 0)) != 0 {
|
||||
if costIcrm.RecurrentFee != nil {
|
||||
rcrntCost := utils.MultiplyBig(
|
||||
utils.DivideBig(aUnits, costIcrm.Increment.Big),
|
||||
costIcrm.RecurrentFee.Big)
|
||||
|
||||
@@ -434,7 +434,9 @@ func TestMaxDebitUsageFromConcretes(t *testing.T) {
|
||||
cb1.blnCfg.Units = utils.NewDecimal(500, 0)
|
||||
cb2.blnCfg.Units = utils.NewDecimal(500, 0)
|
||||
if _, err := maxDebitAbstractsFromConcretes(decimal.New(1100, 0), utils.EmptyString,
|
||||
[]*concreteBalance{cb1, cb2}, nil, new(utils.CGREvent),
|
||||
[]*concreteBalance{cb1, cb2}, nil, &utils.CGREvent{
|
||||
ID: "Unique_id",
|
||||
},
|
||||
nil, nil, nil, nil, &utils.CostIncrement{
|
||||
Increment: utils.NewDecimal(1, 0),
|
||||
RecurrentFee: utils.NewDecimal(1, 0),
|
||||
@@ -532,6 +534,7 @@ func TestRestoreAccount2(t *testing.T) { //coverage purpose
|
||||
}
|
||||
|
||||
log.SetOutput(os.Stderr)
|
||||
utils.Logger.SetLogLevel(6)
|
||||
}
|
||||
|
||||
func TestRestoreAccount3(t *testing.T) { //coverage purpose
|
||||
|
||||
Reference in New Issue
Block a user