Convert CDR.Opts[*accountsCost] to *utils.EventCharges

This commit is contained in:
armirveliaj
2025-01-29 11:20:58 -05:00
committed by Dan Christian Bogos
parent f89cad421e
commit c34ae82539
2 changed files with 11 additions and 13 deletions

View File

@@ -256,9 +256,9 @@ func (cdrS *CDRServer) processEvents(ctx *context.Context, evs []*utils.CGREvent
continue
}
if ecCostIface, wasCharged := cgrEv.APIOpts[utils.MetaAccountSCost]; wasCharged {
ecCostMap, ok := ecCostIface.(map[string]any)
ecCostMap, ok := ecCostIface.(*utils.EventCharges)
if !ok {
return nil, fmt.Errorf("expected %s to be a map[string]any, got %T", utils.MetaAccountSCost, ecCostIface)
return nil, fmt.Errorf("expected %s to be a *utils.EventCharges, got %T", utils.MetaAccountSCost, ecCostMap)
}
// before converting into EventChargers, we must get the JSON encoding and Unmarshal it into an EventChargers

View File

@@ -2350,8 +2350,8 @@ func TestCDRsProcessEventMockThdsEcCostIface(t *testing.T) {
APIOpts: map[string]any{
utils.MetaAccounts: true,
"*context": utils.MetaCDRs,
utils.MetaAccountSCost: map[string]any{
"Concretes": utils.NewDecimal(400, 0),
utils.MetaAccountSCost: &utils.EventCharges{
Concretes: utils.NewDecimal(400, 0),
},
},
}
@@ -2388,13 +2388,13 @@ func TestCDRsProcessEventMockThdsEcCostIfaceMarshalErr(t *testing.T) {
APIOpts: map[string]any{
utils.MetaAccounts: true,
"*context": utils.MetaCDRs,
utils.MetaAccountSCost: map[string]any{
"Concretes": make(chan string),
utils.MetaAccountSCost: &utils.EventCharges{
Concretes: utils.NewDecimal(1, 2),
},
},
}
_, err := newCDRSrv.processEvents(context.Background(), []*utils.CGREvent{cgrEv})
if err == nil || err.Error() != "json: unsupported type: chan string" {
if err == nil || err.Error() != "PARTIALLY_EXECUTED" {
t.Errorf("\nExpected <%+v> \n, received <%+v>", "json: unsupported type: chan string", err)
}
}
@@ -2424,14 +2424,12 @@ func TestCDRsProcessEventMockThdsEcCostIfaceUnmarshalErr(t *testing.T) {
cgrEv := &utils.CGREvent{
APIOpts: map[string]any{
utils.MetaAccounts: true,
"*context": utils.MetaCDRs,
utils.MetaAccountSCost: map[string]any{
"Charges": "not unmarshable",
},
utils.MetaAccounts: true,
"*context": utils.MetaCDRs,
utils.MetaAccountSCost: &utils.EventCharges{},
},
}
expErr := "json: cannot unmarshal string into Go struct field EventCharges.Charges of type []*utils.ChargeEntry"
expErr := "PARTIALLY_EXECUTED"
_, err := newCDRSrv.processEvents(context.Background(), []*utils.CGREvent{cgrEv})
if err == nil || err.Error() != expErr {
t.Errorf("\nExpected <%+v> \n, received <%+v>", expErr, err)