Updated MapEvent.AsCDR to initialize the CostDetails. Fixes #2247

This commit is contained in:
Trial97
2020-06-30 11:30:41 +03:00
parent 5a59cb063e
commit b76d626f6f
6 changed files with 46 additions and 7 deletions

View File

@@ -265,6 +265,11 @@ func (me MapEvent) AsCDR(cfg *config.CGRConfig, tnt, tmz string) (cdr *CDR, err
}
}
}
if cdr.CostDetails == nil {
cdr.CostDetails = NewBareEventCost()
} else {
cdr.CostDetails.initCache()
}
if cfg != nil {
cdr.AddDefaults(cfg)
}

View File

@@ -311,7 +311,7 @@ func TestMapEventAsMapString(t *testing.T) {
func TestMapEventAsCDR(t *testing.T) {
me := NewMapEvent(nil)
expected := &CDR{Cost: -1.0, ExtraFields: make(map[string]string)}
expected := &CDR{Cost: -1.0, ExtraFields: make(map[string]string), CostDetails: NewBareEventCost()}
if rply, err := me.AsCDR(nil, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rply) {
@@ -330,6 +330,7 @@ func TestMapEventAsCDR(t *testing.T) {
Tenant: cfg.GeneralCfg().DefaultTenant,
Category: cfg.GeneralCfg().DefaultCategory,
ExtraFields: make(map[string]string),
CostDetails: NewBareEventCost(),
}
if rply, err := me.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -371,7 +372,8 @@ func TestMapEventAsCDR(t *testing.T) {
me = MapEvent{"ExtraField1": 5, "ExtraField2": "extra"}
expected = &CDR{
Cost: -1.0,
Cost: -1.0,
CostDetails: NewBareEventCost(),
ExtraFields: map[string]string{
"ExtraField1": "5",
"ExtraField2": "extra",
@@ -403,6 +405,7 @@ func TestMapEventAsCDR(t *testing.T) {
Tenant: cfg.GeneralCfg().DefaultTenant,
Category: cfg.GeneralCfg().DefaultCategory,
ExtraInfo: "ACCOUNT_NOT_FOUND",
CostDetails: NewBareEventCost(),
}
if rply, err := me.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -446,7 +449,8 @@ func TestMapEventAsCDR(t *testing.T) {
"ExtraField1": "5",
"ExtraField2": "extra",
},
ExtraInfo: "ACCOUNT_NOT_FOUND",
ExtraInfo: "ACCOUNT_NOT_FOUND",
CostDetails: NewBareEventCost(),
}
if rply, err := me.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -629,6 +633,7 @@ func TestMapEventAsCDR(t *testing.T) {
},
},
}
ec1.initCache()
me = MapEvent{
"ExtraField1": 5,
"Source": 1001,

View File

@@ -625,7 +625,7 @@ func TestSafEventAsMapString(t *testing.T) {
func TestSafEventAsCDR(t *testing.T) {
se := SafEvent{Me: NewMapEvent(nil)}
expected := &CDR{Cost: -1.0, ExtraFields: make(map[string]string)}
expected := &CDR{Cost: -1.0, ExtraFields: make(map[string]string), CostDetails: NewBareEventCost()}
if rply, err := se.AsCDR(nil, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rply) {
@@ -644,6 +644,7 @@ func TestSafEventAsCDR(t *testing.T) {
Tenant: cfg.GeneralCfg().DefaultTenant,
Category: cfg.GeneralCfg().DefaultCategory,
ExtraFields: make(map[string]string),
CostDetails: NewBareEventCost(),
}
if rply, err := se.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -676,7 +677,8 @@ func TestSafEventAsCDR(t *testing.T) {
}
se = SafEvent{Me: MapEvent{"ExtraField1": 5, "ExtraField2": "extra"}}
expected = &CDR{
Cost: -1.0,
Cost: -1.0,
CostDetails: NewBareEventCost(),
ExtraFields: map[string]string{
"ExtraField1": "5",
"ExtraField2": "extra",
@@ -706,6 +708,7 @@ func TestSafEventAsCDR(t *testing.T) {
RequestType: cfg.GeneralCfg().DefaultReqType,
Tenant: cfg.GeneralCfg().DefaultTenant,
Category: cfg.GeneralCfg().DefaultCategory,
CostDetails: NewBareEventCost(),
}
if rply, err := se.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -739,6 +742,7 @@ func TestSafEventAsCDR(t *testing.T) {
ToR: utils.VOICE,
RequestType: cfg.GeneralCfg().DefaultReqType,
Category: cfg.GeneralCfg().DefaultCategory,
CostDetails: NewBareEventCost(),
}
if rply, err := se.AsCDR(cfg, "itsyscom.com", utils.EmptyString); err != nil {
t.Error(err)