From c34ae8253975361e25fa6f8ebe12ce70a8f230d3 Mon Sep 17 00:00:00 2001 From: armirveliaj Date: Wed, 29 Jan 2025 11:20:58 -0500 Subject: [PATCH] Convert CDR.Opts[*accountsCost] to *utils.EventCharges --- cdrs/cdrs.go | 4 ++-- cdrs/cdrs_test.go | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cdrs/cdrs.go b/cdrs/cdrs.go index f398c0bb7..5cc668684 100644 --- a/cdrs/cdrs.go +++ b/cdrs/cdrs.go @@ -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 diff --git a/cdrs/cdrs_test.go b/cdrs/cdrs_test.go index e9b4c5b92..6e2106530 100644 --- a/cdrs/cdrs_test.go +++ b/cdrs/cdrs_test.go @@ -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)