Files
cgrates/utils/accountprofile_test.go

119 lines
3.3 KiB
Go

/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package utils
import (
"reflect"
"testing"
"time"
"github.com/ericlagergren/decimal"
)
func TestCloneBalance(t *testing.T) {
expBlc := &Balance{
ID: "TEST_ID1",
FilterIDs: []string{"*string:~*req.Account:1001"},
Weight: 1.1,
Blocker: true,
Type: "*abstract",
Opts: map[string]interface{}{
"Destination": 10,
},
CostIncrements: []*CostIncrement{
{
FilterIDs: []string{"*string:~*req.Account:1001"},
Increment: &Decimal{decimal.New(1, 1)},
FixedFee: &Decimal{decimal.New(75, 1)},
RecurrentFee: &Decimal{decimal.New(20, 1)},
},
},
CostAttributes: []string{"attr1", "attr2"},
UnitFactors: []*UnitFactor{
{
FilterIDs: []string{"*string:~*req.Account:1001"},
Factor: &Decimal{decimal.New(20, 2)},
},
},
Units: &Decimal{decimal.New(125, 3)},
}
if rcv := expBlc.Clone(); !reflect.DeepEqual(rcv, expBlc) {
t.Errorf("Expected %+v \n, received %+v", ToJSON(expBlc), ToJSON(rcv))
}
}
func TestCloneAccountProfile(t *testing.T) {
actPrf := &AccountProfile{
Tenant: "cgrates.org",
ID: "Profile_id1",
FilterIDs: []string{"*string:~*req.Account:1001"},
ActivationInterval: &ActivationInterval{
ActivationTime: time.Date(2020, 7, 21, 10, 0, 0, 0, time.UTC),
ExpiryTime: time.Date(2020, 7, 22, 10, 0, 0, 0, time.UTC),
},
Weight: 2.4,
Opts: map[string]interface{}{
"Destination": 10,
},
Balances: []*Balance{
{
ID: "VoiceBalance",
FilterIDs: []string{"*string:~*req.Account:1001"},
Weight: 1.1,
Blocker: true,
Type: "*abstract",
Opts: map[string]interface{}{
"Destination": 10,
},
CostIncrements: []*CostIncrement{
{
FilterIDs: []string{"*string:~*req.Account:1001"},
Increment: &Decimal{decimal.New(1, 1)},
FixedFee: &Decimal{decimal.New(75, 1)},
RecurrentFee: &Decimal{decimal.New(20, 1)},
},
},
CostAttributes: []string{"attr1", "attr2"},
UnitFactors: []*UnitFactor{
{
FilterIDs: []string{"*string:~*req.Account:1001"},
Factor: &Decimal{decimal.New(20, 2)},
},
},
Units: &Decimal{decimal.New(125, 3)},
},
},
ThresholdIDs: []string{"*none"},
}
if rcv := actPrf.Clone(); !reflect.DeepEqual(rcv, actPrf) {
t.Errorf("Expected %+v, received %+v", ToJSON(actPrf), ToJSON(rcv))
}
}
func TestTenantIDAccountProfile(t *testing.T) {
actPrf := &AccountProfile{
Tenant: "cgrates.org",
ID: "test_ID1",
}
exp := "cgrates.org:test_ID1"
if rcv := actPrf.TenantID(); rcv != exp {
t.Errorf("Expected %+v, received %+v", exp, rcv)
}
}