From c7ab22d43ea7e33e9b15188a0d16d2b2f90e62e4 Mon Sep 17 00:00:00 2001 From: armirveliaj Date: Tue, 3 Dec 2024 10:24:30 -0500 Subject: [PATCH] Add unit tests on engine --- engine/libeventcost_test.go | 32 ++++++++++++++++++++++++++++++++ engine/libstats_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/engine/libeventcost_test.go b/engine/libeventcost_test.go index 2598ba9fe..e2b544371 100644 --- a/engine/libeventcost_test.go +++ b/engine/libeventcost_test.go @@ -1606,3 +1606,35 @@ func TestRatingFieldAsInterface(t *testing.T) { t.Error("Expected error for invalid field within rating") } } + +func TestBalanceChargesClone(t *testing.T) { + t.Run("Normal", func(t *testing.T) { + original := &BalanceCharge{ + AccountID: "account1", + BalanceUUID: "uuid1", + RatingID: "rating1", + Units: 100.5, + BalanceFactor: 1.25, + ExtraChargeID: "extraCharge01", + } + cloned := original.Clone() + if cloned == nil { + t.Errorf("Expected cloned BalanceCharge to be non-nil, but got nil") + } + if cloned.AccountID != original.AccountID || cloned.BalanceUUID != original.BalanceUUID || + cloned.RatingID != original.RatingID || cloned.Units != original.Units || + cloned.BalanceFactor != original.BalanceFactor || cloned.ExtraChargeID != original.ExtraChargeID { + t.Errorf("Cloned BalanceCharge does not match original. Expected %+v, but got %+v", original, cloned) + } + if cloned == original { + t.Errorf("Expected original and cloned BalanceCharge to be different instances, but they are the same") + } + }) + t.Run("NilReceiver", func(t *testing.T) { + var original *BalanceCharge + cloned := original.Clone() + if cloned != nil { + t.Errorf("Expected cloned BalanceCharge to be nil, but got %+v", cloned) + } + }) +} diff --git a/engine/libstats_test.go b/engine/libstats_test.go index 7ac732499..a62c9c324 100644 --- a/engine/libstats_test.go +++ b/engine/libstats_test.go @@ -1176,3 +1176,31 @@ func TestStatQueueUnmarshalJSON(t *testing.T) { } } + +func TestLibRoutesRouteIDs(t *testing.T) { + sortedRoutesList := SortedRoutesList{ + { + Routes: []*SortedRoute{ + {RouteID: "1"}, + {RouteID: "2"}, + }, + }, + { + Routes: []*SortedRoute{ + {RouteID: "3"}, + {RouteID: "4"}, + }, + }, + } + expectedIDs := []string{"1", "2", "3", "4"} + actualIDs := sortedRoutesList.RouteIDs() + if len(actualIDs) != len(expectedIDs) { + t.Errorf("expected length %d, got %d", len(expectedIDs), len(actualIDs)) + return + } + for i := range expectedIDs { + if actualIDs[i] != expectedIDs[i] { + t.Errorf("at index %d, expected %s, got %s", i, expectedIDs[i], actualIDs[i]) + } + } +}