mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 15:18:44 +05:00
Update and add integration tests for accounts
This commit is contained in:
committed by
Dan Christian Bogos
parent
cb3b16133a
commit
71f9cfb8b6
@@ -56,7 +56,8 @@ func TestAccountSv1IT(t *testing.T) {
|
||||
testAccountSv1SimpleDebit,
|
||||
testAccountSv1DebitMultipleAcc,
|
||||
testAccountSv1DebitMultipleAccLimited,
|
||||
testAccountSv1DebitWithAttributeS,
|
||||
testAccountSv1DebitWithAttributeSandRateS,
|
||||
testAccountSv1DebitWithRateS,
|
||||
}
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
@@ -730,7 +731,7 @@ func testAccountSv1DebitMultipleAccLimited(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testAccountSv1DebitWithAttributeS(t *testing.T) {
|
||||
func testAccountSv1DebitWithAttributeSandRateS(t *testing.T) {
|
||||
accPrfAPI := &APIAccountProfileWithCache{
|
||||
APIAccountProfile: &utils.APIAccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -827,3 +828,101 @@ func testAccountSv1DebitWithAttributeS(t *testing.T) {
|
||||
t.Errorf("Expecting : %+v, received: %s", decimal.New(99, 0), reply2.Balances["Balance1"].Units)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccountSv1DebitWithRateS(t *testing.T) {
|
||||
accPrfAPI := &APIAccountProfileWithCache{
|
||||
APIAccountProfile: &utils.APIAccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ACC_WITH_RATES",
|
||||
FilterIDs: []string{"*string:~*req.Account:ACC_WITH_RATES"},
|
||||
Weights: ";10",
|
||||
Balances: map[string]*utils.APIBalance{
|
||||
"Balance1": &utils.APIBalance{
|
||||
ID: "Balance1",
|
||||
Weights: ";10",
|
||||
Type: utils.MetaConcrete,
|
||||
Units: 100,
|
||||
CostIncrements: []*utils.APICostIncrement{
|
||||
{
|
||||
Increment: utils.Float64Pointer(1),
|
||||
RecurrentFee: utils.Float64Pointer(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
},
|
||||
}
|
||||
var reply string
|
||||
if err := acntSRPC.Call(utils.APIerSv1SetAccountProfile, accPrfAPI, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
var err error
|
||||
var convAcc *utils.AccountProfile
|
||||
if convAcc, err = accPrfAPI.AsAccountProfile(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
var reply2 *utils.AccountProfile
|
||||
if err := acntSRPC.Call(utils.APIerSv1GetAccountProfile, &utils.TenantIDWithOpts{
|
||||
TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACC_WITH_RATES"}}, &reply2); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(convAcc, reply2) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", convAcc, reply2)
|
||||
}
|
||||
|
||||
//set a rate profile to be used in case of debit
|
||||
apiRPrf := &engine.APIRateProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RP_Test2",
|
||||
FilterIDs: []string{"*string:~*req.Account:ACC_WITH_RATES"},
|
||||
Weights: ";20",
|
||||
Rates: map[string]*engine.APIRate{
|
||||
"RT_ALWAYS": {
|
||||
ID: "RT_ALWAYS",
|
||||
Weights: ";0",
|
||||
ActivationTimes: "* * * * *",
|
||||
IntervalRates: []*engine.APIIntervalRate{
|
||||
{
|
||||
IntervalStart: "0",
|
||||
RecurrentFee: utils.Float64Pointer(0.5),
|
||||
Increment: utils.Float64Pointer(2),
|
||||
Unit: utils.Float64Pointer(2),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := acntSRPC.Call(utils.APIerSv1SetRateProfile,
|
||||
&APIRateProfileWithCache{
|
||||
APIRateProfileWithOpts: &engine.APIRateProfileWithOpts{
|
||||
APIRateProfile: apiRPrf},
|
||||
}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
|
||||
}
|
||||
|
||||
var eEc *utils.ExtEventCharges
|
||||
if err := acntSRPC.Call(utils.AccountSv1DebitUsage,
|
||||
&utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testAccountSv1DebitWithAttributeS",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "ACC_WITH_RATES",
|
||||
utils.Usage: "20",
|
||||
}}}, &eEc); err != nil {
|
||||
t.Error(err)
|
||||
} else if eEc.Usage == nil || *eEc.Usage != 20.0 {
|
||||
t.Fatalf("received usage: %v", *eEc.Usage)
|
||||
}
|
||||
|
||||
if err := acntSRPC.Call(utils.APIerSv1GetAccountProfile, &utils.TenantIDWithOpts{
|
||||
TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACC_WITH_RATES"}}, &reply2); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(95, 0)) != 0 {
|
||||
t.Errorf("Expecting : %+v, received: %s", decimal.New(95, 0), reply2.Balances["Balance1"].Units)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user