Add unit tests on engine

This commit is contained in:
armirveliaj
2024-06-03 10:06:25 -04:00
committed by Dan Christian Bogos
parent ae7c27da0a
commit 044e56a6a4
2 changed files with 105 additions and 0 deletions

View File

@@ -3423,3 +3423,26 @@ func TestEngineNewAccountSummaryFromJSON(t *testing.T) {
})
}
}
func TestAccountSummaryString(t *testing.T) {
account := &AccountSummary{
Tenant: "cgrates.org",
ID: "2012",
AllowNegative: true,
Disabled: false,
BalanceSummaries: BalanceSummaries{
&BalanceSummary{
Factors: ValueFactors{
"factor1": 1.0,
"factor2": 2.0,
},
},
},
}
result := account.String()
var parsedResult map[string]interface{}
err := json.Unmarshal([]byte(result), &parsedResult)
if err != nil {
t.Errorf("Error unmarshalling result: %v", err)
}
}

View File

@@ -536,3 +536,85 @@ func TestBalanceFilterModifyBalance(t *testing.T) {
}
}
func TestBalanceFilterSetValue(t *testing.T) {
t.Run("when Value is nil", func(t *testing.T) {
bp := &BalanceFilter{}
bp.SetValue(42.0)
if bp.Value == nil {
t.Fatalf("expected Value to be non-nil")
}
if bp.Value.Static != 42.0 {
t.Errorf("expected Static to be 42.0, got %f", bp.Value.Static)
}
})
t.Run("when Value is not nil", func(t *testing.T) {
initialFormula := &utils.ValueFormula{Static: 10.0}
bp := &BalanceFilter{Value: initialFormula}
bp.SetValue(42.0)
if bp.Value == nil {
t.Fatalf("expected Value to be non-nil")
}
if bp.Value.Static != 42.0 {
t.Errorf("expected Static to be 42.0, got %f", bp.Value.Static)
}
})
}
func TestBalanceFilterGetTimingIDs(t *testing.T) {
t.Run("when BalanceFilter is nil", func(t *testing.T) {
var bp *BalanceFilter
result := bp.GetTimingIDs()
if len(result) != 0 {
t.Errorf("expected empty StringMap, got %v", result)
}
})
t.Run("when TimingIDs is nil", func(t *testing.T) {
bp := &BalanceFilter{}
result := bp.GetTimingIDs()
if len(result) != 0 {
t.Errorf("expected empty StringMap, got %v", result)
}
})
t.Run("when TimingIDs is not nil", func(t *testing.T) {
timingIDs := utils.StringMap{"key1": false}
bp := &BalanceFilter{TimingIDs: &timingIDs}
result := bp.GetTimingIDs()
if len(result) != 1 || result["key1"] != false {
t.Errorf("expected StringMap with key1=value1, got %v", result)
}
})
}
func TestBalanceFilterGetFactors(t *testing.T) {
t.Run("when BalanceFilter is nil", func(t *testing.T) {
var bp *BalanceFilter
result := bp.GetFactors()
if result != nil {
t.Errorf("expected nil, got %v", result)
}
})
t.Run("when Factors is nil", func(t *testing.T) {
bp := &BalanceFilter{}
result := bp.GetFactors()
if result != nil {
t.Errorf("expected nil, got %v", result)
}
})
t.Run("when Factors is not nil", func(t *testing.T) {
expectedFactors := ValueFactors{"key1": 42.0, "key2": 10.5}
bp := &BalanceFilter{Factors: &expectedFactors}
result := bp.GetFactors()
if result == nil {
t.Fatalf("expected non-nil, got nil")
}
if len(result) != len(expectedFactors) {
t.Errorf("expected ValueFactors length %d, got %d", len(expectedFactors), len(result))
}
for k, v := range expectedFactors {
if result[k] != v {
t.Errorf("expected ValueFactors[%s]=%f, got %f", k, v, result[k])
}
}
})
}