AccountS - concreteBalance.debitUnits taking DataProvider

This commit is contained in:
DanB
2021-01-15 19:54:18 +01:00
parent 649af0afc8
commit 44eedd634b
4 changed files with 16 additions and 22 deletions

View File

@@ -96,7 +96,7 @@ func (aB *abstractBalance) balanceLimit() (bL *utils.Decimal) {
}
// processAttributeS will process the event with AttributeS
func (aB *abstractBalance) processAttributeS(cgrEv *utils.CGREventWithOpts) (rplyEv *engine.AttrSProcessEventReply, err error) {
func (aB *abstractBalance) processAttributeS(cgrEv *utils.CGREvent) (rplyEv *engine.AttrSProcessEventReply, err error) {
if len(aB.attrSConns) == 0 {
return rplyEv, utils.NewErrNotConnected(utils.AttributeS)
}
@@ -110,9 +110,9 @@ func (aB *abstractBalance) processAttributeS(cgrEv *utils.CGREventWithOpts) (rpl
Context: utils.StringPointer(utils.FirstNonEmpty(
engine.MapEvent(cgrEv.Opts).GetStringIgnoreErrors(utils.OptsContext),
utils.MetaAccountS)),
CGREventWithOpts: cgrEv,
AttributeIDs: aB.blnCfg.CostAttributes,
ProcessRuns: procRuns,
CGREvent: cgrEv,
AttributeIDs: aB.blnCfg.CostAttributes,
ProcessRuns: procRuns,
}
err = aB.connMgr.Call(aB.attrSConns, nil, utils.AttributeSv1ProcessEvent,
attrArgs, &rplyEv)
@@ -121,7 +121,7 @@ func (aB *abstractBalance) processAttributeS(cgrEv *utils.CGREventWithOpts) (rpl
// debitUsageFromConcrete attempts to debit the usage out of concrete balances
func (aB *abstractBalance) debitUsageFromConcrete(usage *utils.Decimal, costIcrm *utils.CostIncrement,
cgrEv *utils.CGREventWithOpts) (dbtedUsage *utils.Decimal, err error) {
cgrEv *utils.CGREvent) (dbtedUsage *utils.Decimal, err error) {
return
}
@@ -155,8 +155,7 @@ func (aB *abstractBalance) debitUsage(usage *utils.Decimal, startTime time.Time,
return
}
if len(rplyAttrS.AlteredFields) != 0 { // event was altered
cgrEv.CGREvent = rplyAttrS.CGREvent
cgrEv.Opts = rplyAttrS.Opts
cgrEv = rplyAttrS.CGREvent
}
}
@@ -181,7 +180,7 @@ func (aB *abstractBalance) debitUsage(usage *utils.Decimal, startTime time.Time,
// unitFactor
var uF *utils.UnitFactor
if uF, err = aB.unitFactor(cgrEv.CGREvent.Tenant, evNm); err != nil {
if uF, err = aB.unitFactor(cgrEv.Tenant, evNm); err != nil {
return
}

View File

@@ -114,23 +114,18 @@ func (cB *concreteBalance) debitUsage(usage *utils.Decimal, startTime time.Time,
// debitUnits is a direct debit of balance units
func (cB *concreteBalance) debitUnits(dUnts *utils.Decimal, incrm *utils.Decimal,
cgrEv *utils.CGREvent) (dbted *utils.Decimal, uF *utils.UnitFactor, err error) {
evNm := utils.MapStorage{
utils.MetaOpts: cgrEv.Opts,
utils.MetaReq: cgrEv.Event,
}
tnt string, ev utils.DataProvider) (dbted *utils.Decimal, uF *utils.UnitFactor, err error) {
// pass the general balance filters
var pass bool
if pass, err = cB.fltrS.Pass(cgrEv.Tenant, cB.blnCfg.FilterIDs, evNm); err != nil {
if pass, err = cB.fltrS.Pass(tnt, cB.blnCfg.FilterIDs, ev); err != nil {
return
} else if !pass {
return nil, nil, utils.ErrFilterNotPassingNoCaps
}
// unitFactor
if uF, err = cB.unitFactor(cgrEv.Tenant, evNm); err != nil {
if uF, err = cB.unitFactor(tnt, ev); err != nil {
return
}

View File

@@ -47,7 +47,7 @@ func TestCBDebitUnits(t *testing.T) {
}
toDebit := utils.NewDecimal(6, 0)
if dbted, uFctr, err := cb.debitUnits(toDebit, utils.NewDecimal(1, 0),
&utils.CGREvent{Tenant: "cgrates.org"}); err != nil {
"cgrates.org", utils.MapStorage{}); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(cb.blnCfg.UnitFactors[0], uFctr) {
t.Errorf("received unit factor: %+v", uFctr)
@@ -71,7 +71,7 @@ func TestCBDebitUnits(t *testing.T) {
if dbted, _, err := cb.debitUnits(
utils.NewDecimal(25, 1), //2.5
utils.NewDecimal(1, 1), //0.1
&utils.CGREvent{Tenant: "cgrates.org"}); err != nil {
"cgrates.org", utils.MapStorage{}); err != nil {
t.Error(err)
} else if dbted.Cmp(decimal.New(22, 1)) != 0 { // only 1.2 is possible due to increment
t.Errorf("debited: %s, cmp: %v", dbted, dbted.Cmp(new(decimal.Big).SetFloat64(1.2)))
@@ -93,7 +93,7 @@ func TestCBDebitUnits(t *testing.T) {
if dbted, _, err := cb.debitUnits(
utils.NewDecimal(25, 1), //2.5
utils.NewDecimal(1, 1), //0.1
&utils.CGREvent{Tenant: "cgrates.org"}); err != nil {
"cgrates.org", utils.MapStorage{}); err != nil {
t.Error(err)
} else if dbted.Cmp(decimal.New(25, 1)) != 0 { // only 1.2 is possible due to increment
t.Errorf("debited: %s, cmp: %v", dbted, dbted.Cmp(new(decimal.Big).SetFloat64(1.2)))
@@ -115,7 +115,7 @@ func TestCBDebitUnits(t *testing.T) {
if dbted, _, err := cb.debitUnits(
utils.NewDecimal(25, 1), //2.5
utils.NewDecimal(1, 1), //0.1
&utils.CGREvent{Tenant: "cgrates.org"}); err != nil {
"cgrates.org", utils.MapStorage{}); err != nil {
t.Error(err)
} else if dbted.Cmp(decimal.New(7, 1)) != 0 { // only 1.2 is possible due to increment
t.Errorf("debited: %s, cmp: %v", dbted, dbted.Cmp(new(decimal.Big).SetFloat64(1.2)))

View File

@@ -44,7 +44,7 @@ func TestAccountSCoverage(t *testing.T) {
actRPC := make(chan rpcclient.ClientConnector, 1)
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
actS := NewAccountService(cfg, db,
chS, filterSChan, server, actRPC,
chS, filterSChan, nil, server, actRPC,
anz, srvDep)
if actS == nil {
t.Errorf("\nExpecting <nil>,\n Received <%+v>", utils.ToJSON(actS))
@@ -87,7 +87,7 @@ func TestAccountSCoverage(t *testing.T) {
if actS2.IsRunning() {
t.Errorf("Expected service to be down")
}
actS2.acts = accounts.NewAccountS(cfg, &engine.FilterS{}, &engine.DataManager{})
actS2.acts = accounts.NewAccountS(cfg, &engine.FilterS{}, nil, &engine.DataManager{})
if !actS2.IsRunning() {
t.Errorf("Expected service to be running")
}