mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Worked in accounts package
This commit is contained in:
committed by
Dan Christian Bogos
parent
5073a7bda2
commit
966f3c2c93
@@ -123,6 +123,7 @@ func (aS *AccountS) matchingAccountsForEvent(tnt string, cgrEv *utils.CGREvent,
|
||||
var weight float64
|
||||
if weight, err = engine.WeightFromDynamics(qAcnt.Weights,
|
||||
aS.fltrS, cgrEv.Tenant, evNm); err != nil {
|
||||
guardian.Guardian.UnguardIDs(refID)
|
||||
return
|
||||
}
|
||||
acnts = append(acnts, &utils.AccountProfileWithWeight{qAcnt, weight, refID})
|
||||
|
||||
@@ -69,6 +69,7 @@ func (dB *dataDBMockErrorNotFound) GetAccountProfileDrv(string, string) (*utils.
|
||||
}
|
||||
|
||||
func TestMatchingAccountsForEventMockingErrors(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
fltr := engine.NewFilterS(cfg, nil, nil)
|
||||
|
||||
@@ -134,6 +135,7 @@ func TestMatchingAccountsForEventMockingErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMatchingAccountsForEvent(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
@@ -227,6 +229,7 @@ func TestMatchingAccountsForEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccountDebit(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
@@ -320,6 +323,7 @@ func TestAccountDebit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccountsDebit(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
@@ -350,6 +354,23 @@ func TestAccountsDebit(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
"ConcreteBalance2": &utils.Balance{
|
||||
ID: "ConcreteBalance2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(213, 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(1, 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -371,21 +392,636 @@ func TestAccountsDebit(t *testing.T) {
|
||||
}
|
||||
delete(cgrEvent.Event, utils.Usage)
|
||||
|
||||
cgrEvent.Opts[utils.MetaUsage] = "not_time_format"
|
||||
if _, err := accnts.accountsDebit(accntsPrf, cgrEvent, false, false); err != nil {
|
||||
t.Error(err)
|
||||
cgrEvent.Event[utils.MetaUsage] = "not_time_format"
|
||||
expected = "time: invalid duration \"not_time_format\""
|
||||
if _, err := accnts.accountsDebit(accntsPrf, cgrEvent, false, false); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
cgrEvent.Opts[utils.MetaUsage] = "55s"
|
||||
delete(cgrEvent.Event, utils.MetaUsage)
|
||||
|
||||
if _, err := accnts.accountsDebit(accntsPrf, cgrEvent, false, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cgrEvent.Event[utils.MetaUsage] = "0"
|
||||
|
||||
cgrEvent.Event[utils.Usage] = "55s"
|
||||
if _, err := accnts.accountsDebit(accntsPrf, cgrEvent, false, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cgrEvent.Event[utils.MetaUsage] = "55s"
|
||||
|
||||
accntsPrf[0].Balances["AbstractBalance1"].Weights[0].FilterIDs = []string{"invalid_filter_format"}
|
||||
expected = "NOT_FOUND:invalid_filter_format"
|
||||
if _, err := accnts.accountsDebit(accntsPrf, cgrEvent, false, true); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
accntsPrf[0].Balances["AbstractBalance1"].Weights[0].FilterIDs = []string{}
|
||||
|
||||
cgrEvent.Event[utils.Usage] = "200ns"
|
||||
expectedUsage := &utils.Decimal{decimal.New(0, 0)}
|
||||
if evCh, err := accnts.accountsDebit(accntsPrf, cgrEvent, false, false); err != nil {
|
||||
if evCh, err := accnts.accountsDebit(accntsPrf, cgrEvent, true, true); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedUsage, evCh.Usage) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expectedUsage), utils.ToJSON(evCh.Usage))
|
||||
}
|
||||
|
||||
accntsPrf[0].Balances["ConcreteBalance2"].Units = &utils.Decimal{decimal.New(213, 0)}
|
||||
accnts.dm = nil
|
||||
expected = "NO_DATA_BASE_CONNECTION"
|
||||
if _, err := accnts.accountsDebit(accntsPrf, cgrEvent, true, true); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1AccountProfilesForEvent(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltr := engine.NewFilterS(cfg, nil, dm)
|
||||
accnts := NewAccountS(cfg, fltr, nil, dm)
|
||||
|
||||
accPrf := &utils.AccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "1004",
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2020, 7, 21, 0, 0, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2020, 7, 21, 10, 0, 0, 0, time.UTC),
|
||||
},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
FilterIDs: []string{"invalid_filter_format"},
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1004"},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"AbstractBalance1": &utils.Balance{
|
||||
ID: "AbstractBalance1",
|
||||
|
||||
Type: utils.MetaAbstract,
|
||||
Units: &utils.Decimal{decimal.New(0, 0)},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := accnts.dm.SetAccountProfile(accPrf, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
args := &utils.ArgsAccountsForEvent{
|
||||
CGREvent: &utils.CGREvent{
|
||||
ID: "TestMatchingAccountsForEvent",
|
||||
Tenant: "cgrates.org",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1004",
|
||||
},
|
||||
},
|
||||
}
|
||||
rply := []*utils.AccountProfile{}
|
||||
|
||||
expected := "SERVER_ERROR: NOT_FOUND:invalid_filter_format"
|
||||
if err := accnts.V1AccountProfilesForEvent(args, &rply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
|
||||
accPrf.Weights[0].FilterIDs = []string{}
|
||||
if err := accnts.dm.SetAccountProfile(accPrf, true); err != nil {
|
||||
t.Error(err)
|
||||
} else if err := accnts.V1AccountProfilesForEvent(args, &rply); err != nil {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
} else if !reflect.DeepEqual(rply[0], accPrf) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(rply[0]), utils.ToJSON(accPrf))
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1MaxAbstracts(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltr := engine.NewFilterS(cfg, nil, dm)
|
||||
accnts := NewAccountS(cfg, fltr, nil, dm)
|
||||
|
||||
accPrf := &utils.AccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1MaxAbstracts",
|
||||
Weights: []*utils.DynamicWeight{
|
||||
{
|
||||
FilterIDs: []string{"invalid_filter"},
|
||||
Weight: 0,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1004"},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"AbstractBalance1": &utils.Balance{
|
||||
ID: "AbstractBalance1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 25,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaAbstract,
|
||||
Units: &utils.Decimal{decimal.New(int64(40*time.Second), 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ConcreteBalance2": &utils.Balance{
|
||||
ID: "ConcreteBalance2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
FilterIDs: []string{"invalid_filter"},
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(213, 0)},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := accnts.dm.SetAccountProfile(accPrf, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
args := &utils.ArgsAccountsForEvent{
|
||||
CGREvent: &utils.CGREvent{
|
||||
ID: "TestMatchingAccountsForEvent",
|
||||
Tenant: "cgrates.org",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1004",
|
||||
utils.Usage: "210ns",
|
||||
},
|
||||
},
|
||||
}
|
||||
reply := utils.ExtEventCharges{}
|
||||
expected := "SERVER_ERROR: NOT_FOUND:invalid_filter"
|
||||
if err := accnts.V1MaxAbstracts(args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
accPrf.Weights[0].FilterIDs = []string{}
|
||||
|
||||
expected = "NOT_FOUND:invalid_filter"
|
||||
if err := accnts.V1MaxAbstracts(args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
delete(accPrf.Balances, "ConcreteBalance2")
|
||||
|
||||
exEvCh := utils.ExtEventCharges{
|
||||
Usage: utils.Float64Pointer(210),
|
||||
}
|
||||
if err := accnts.V1MaxAbstracts(args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(exEvCh, reply) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(exEvCh), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1DebitAbstracts(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltr := engine.NewFilterS(cfg, nil, dm)
|
||||
accnts := NewAccountS(cfg, fltr, nil, dm)
|
||||
|
||||
accPrf := &utils.AccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1DebitAbstracts",
|
||||
Weights: []*utils.DynamicWeight{
|
||||
{
|
||||
FilterIDs: []string{"invalid_filter"},
|
||||
Weight: 0,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1004"},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"AbstractBalance1": &utils.Balance{
|
||||
ID: "AbstractBalance1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 25,
|
||||
FilterIDs: []string{"invalid_filter"},
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(int64(40*time.Second), 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := accnts.dm.SetAccountProfile(accPrf, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
args := &utils.ArgsAccountsForEvent{
|
||||
CGREvent: &utils.CGREvent{
|
||||
ID: "TestV1DebitID",
|
||||
Tenant: "cgrates.org",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1004",
|
||||
utils.Usage: "27s",
|
||||
},
|
||||
},
|
||||
}
|
||||
reply := utils.ExtEventCharges{}
|
||||
expected := "SERVER_ERROR: NOT_FOUND:invalid_filter"
|
||||
if err := accnts.V1DebitAbstracts(args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
accPrf.Weights[0].FilterIDs = []string{}
|
||||
|
||||
expected = "NOT_FOUND:invalid_filter"
|
||||
if err := accnts.V1DebitAbstracts(args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
accPrf.Balances["AbstractBalance1"].Weights[0].FilterIDs = []string{}
|
||||
|
||||
exEvCh := utils.ExtEventCharges{
|
||||
Usage: utils.Float64Pointer(float64(27 * time.Second)),
|
||||
}
|
||||
if err := accnts.V1DebitAbstracts(args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(exEvCh, reply) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(exEvCh), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1MaxConcretes(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltr := engine.NewFilterS(cfg, nil, dm)
|
||||
accnts := NewAccountS(cfg, fltr, nil, dm)
|
||||
|
||||
accPrf := &utils.AccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1DebitAbstracts",
|
||||
Weights: []*utils.DynamicWeight{
|
||||
{
|
||||
FilterIDs: []string{"invalid_filter"},
|
||||
Weight: 0,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1004"},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"AbstractBalance1": &utils.Balance{
|
||||
ID: "AbstractBalance1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 15,
|
||||
FilterIDs: []string{"invalid_filter"},
|
||||
},
|
||||
},
|
||||
Type: utils.MetaAbstract,
|
||||
Units: &utils.Decimal{decimal.New(int64(40*time.Second), 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ConcreteBalance1": &utils.Balance{
|
||||
ID: "ConcreteBalance1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 25,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(int64(time.Minute), 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ConcreteBalance2": &utils.Balance{
|
||||
ID: "ConcreteBalance2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 5,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(int64(30*time.Second), 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := accnts.dm.SetAccountProfile(accPrf, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
args := &utils.ArgsAccountsForEvent{
|
||||
CGREvent: &utils.CGREvent{
|
||||
ID: "TestV1DebitID",
|
||||
Tenant: "cgrates.org",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1004",
|
||||
utils.Usage: "3m",
|
||||
},
|
||||
},
|
||||
}
|
||||
reply := utils.ExtEventCharges{}
|
||||
expected := "SERVER_ERROR: NOT_FOUND:invalid_filter"
|
||||
if err := accnts.V1MaxConcretes(args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
accPrf.Weights[0].FilterIDs = []string{}
|
||||
|
||||
expected = "NOT_FOUND:invalid_filter"
|
||||
if err := accnts.V1MaxConcretes(args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
accPrf.Balances["AbstractBalance1"].Weights[0].FilterIDs = []string{}
|
||||
|
||||
exEvCh := utils.ExtEventCharges{
|
||||
Usage: utils.Float64Pointer(float64(time.Minute + 30*time.Second)),
|
||||
}
|
||||
if err := accnts.V1MaxConcretes(args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(exEvCh, reply) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(exEvCh), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1DebitConcretes(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltr := engine.NewFilterS(cfg, nil, dm)
|
||||
accnts := NewAccountS(cfg, fltr, nil, dm)
|
||||
|
||||
accPrf := &utils.AccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1DebitAbstracts",
|
||||
Weights: []*utils.DynamicWeight{
|
||||
{
|
||||
FilterIDs: []string{"invalid_filter"},
|
||||
Weight: 0,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1004"},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"AbstractBalance1": &utils.Balance{
|
||||
ID: "AbstractBalance1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 15,
|
||||
FilterIDs: []string{"invalid_filter"},
|
||||
},
|
||||
},
|
||||
Type: utils.MetaAbstract,
|
||||
Units: &utils.Decimal{decimal.New(int64(40*time.Second), 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ConcreteBalance1": &utils.Balance{
|
||||
ID: "ConcreteBalance1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 25,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(int64(time.Minute), 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ConcreteBalance2": &utils.Balance{
|
||||
ID: "ConcreteBalance2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 5,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(int64(30*time.Second), 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := accnts.dm.SetAccountProfile(accPrf, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
args := &utils.ArgsAccountsForEvent{
|
||||
CGREvent: &utils.CGREvent{
|
||||
ID: "TestV1DebitID",
|
||||
Tenant: "cgrates.org",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1004",
|
||||
utils.Usage: "3m",
|
||||
},
|
||||
},
|
||||
}
|
||||
reply := utils.ExtEventCharges{}
|
||||
expected := "SERVER_ERROR: NOT_FOUND:invalid_filter"
|
||||
if err := accnts.V1DebitConcretes(args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
accPrf.Weights[0].FilterIDs = []string{}
|
||||
|
||||
expected = "NOT_FOUND:invalid_filter"
|
||||
if err := accnts.V1DebitConcretes(args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
accPrf.Balances["AbstractBalance1"].Weights[0].FilterIDs = []string{}
|
||||
|
||||
exEvCh := utils.ExtEventCharges{
|
||||
Usage: utils.Float64Pointer(float64(time.Minute + 30*time.Second)),
|
||||
}
|
||||
if err := accnts.V1DebitConcretes(args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(exEvCh, reply) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(exEvCh), utils.ToJSON(reply))
|
||||
}
|
||||
|
||||
//now we will check the debited account
|
||||
rcv, err := accnts.dm.GetAccountProfile("cgrates.org", "TestV1DebitAbstracts")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
accPrf.Balances["ConcreteBalance1"].Units = &utils.Decimal{decimal.New(0, 0)}
|
||||
accPrf.Balances["ConcreteBalance2"].Units = &utils.Decimal{decimal.New(0, 0)}
|
||||
if !reflect.DeepEqual(rcv, accPrf) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(accPrf), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
func TestMultipleAccountsFail(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltr := engine.NewFilterS(cfg, nil, dm)
|
||||
accnts := NewAccountS(cfg, fltr, nil, dm)
|
||||
|
||||
accPrf := []*utils.AccountProfile{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1MaxAbstracts",
|
||||
Weights: []*utils.DynamicWeight{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1004"},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"ConcreteBalance2": &utils.Balance{
|
||||
ID: "ConcreteBalance2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(213, 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(1, 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1MaxAbstracts2",
|
||||
Weights: []*utils.DynamicWeight{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1004"},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"ConcreteBalance2": &utils.Balance{
|
||||
ID: "ConcreteBalance2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(213, 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(1, 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1MaxAbstracts3",
|
||||
Weights: []*utils.DynamicWeight{
|
||||
{
|
||||
FilterIDs: []string{"invalid_format"},
|
||||
Weight: 5,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1004"},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"ConcreteBalance2": &utils.Balance{
|
||||
ID: "ConcreteBalance2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
Type: utils.MetaConcrete,
|
||||
Units: &utils.Decimal{decimal.New(213, 0)},
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
&utils.CostIncrement{
|
||||
Increment: &utils.Decimal{decimal.New(1, 0)},
|
||||
FixedFee: &utils.Decimal{decimal.New(0, 0)},
|
||||
RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := &utils.CGREvent{
|
||||
ID: "TestMatchingAccountsForEvent",
|
||||
Tenant: "cgrates.org",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1004",
|
||||
utils.Usage: "210ns",
|
||||
},
|
||||
}
|
||||
|
||||
if err := accnts.dm.SetAccountProfile(accPrf[0], true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := accnts.dm.SetAccountProfile(accPrf[1], true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := accnts.dm.SetAccountProfile(accPrf[2], true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
expected := "NOT_FOUND:invalid_format"
|
||||
if _, err := accnts.matchingAccountsForEvent("cgrates.org", args,
|
||||
[]string{"TestV1MaxAbstracts", "TestV1MaxAbstracts2", "TestV1MaxAbstracts3"}, true); err != nil {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
|
||||
expected = "NOT_FOUND:invalid_format"
|
||||
if _, err := accnts.matchingAccountsForEvent("cgrates.org", args,
|
||||
[]string{"TestV1MaxAbstracts", "TestV1MaxAbstracts2", "TestV1MaxAbstracts3"}, true); err != nil {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user