mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 22:29:55 +05:00
Tests for tutorial2/accounts
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#ActionsId[0],Action[1],ExtraParameters[2],Filter[3],BalanceId[4],BalanceType[5],Categories[6],DestinationIds[7],RatingSubject[8],SharedGroup[9],ExpiryTime[10],TimingIds[11],Units[12],BalanceWeight[13],BalanceBlocker[14],BalanceDisabled[15],Weight[16]
|
||||
TOPUP_RST_MONETARY_10,*topup_reset,,,*default,*monetary,,,,,,,10,10,,,10
|
||||
TOPUP_RST_5M_VOICE,*topup_reset,,,,*voice,,DST_10,RPF_SPECIAL_BLC,,,,5m,30,,,10
|
||||
TOPUP_RST_10M_VOICE,*topup_reset,,,,*voice,,DST_10,*zero1m,,,,10m,20,,,10
|
||||
TOPUP_RST_100_SMS,*topup_reset,,,,*sms,,DST_50,,,,,100,20,,,10
|
||||
TOPUP_RST_1024_DATA,*topup_reset,,,,*data,,,,,,,1024,20,,,10
|
||||
TOPUP_RST_5M_VOICE,*topup_reset,,,PER_CALL,*voice,,DST_10,RPF_SPECIAL_BLC,,,,10m,10,,,10
|
||||
TOPUP_RST_10M_VOICE,*topup_reset,,,FREE_MINS,*voice,,,*zero1m,,,,5m,20,,,10
|
||||
TOPUP_RST_100_SMS,*topup_reset,,,FREE_SMSes,*sms,,DST_50,,,,,100,20,,,10
|
||||
TOPUP_RST_1024_DATA,*topup_reset,,,FREE_DATA,*data,,,,,,,1024,20,,,10
|
||||
LOG_WARNING,*log,,,,,,,,,,,,,,,10
|
||||
DISABLE_ACCOUNT,*disable_account,,,,,,,,,,,,,,,10
|
||||
|
@@ -134,7 +134,7 @@ func testV1AccLoadTarrifPlans(t *testing.T) {
|
||||
|
||||
func testV1AccGetAccountAfterLoad(t *testing.T) {
|
||||
var reply *engine.Account
|
||||
if err := accRpc.Call("ApierV2.GetAccount",
|
||||
if err := accRpc.Call(utils.ApierV2GetAccount,
|
||||
&utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"},
|
||||
&reply); err != nil {
|
||||
t.Error(err)
|
||||
@@ -266,7 +266,7 @@ func testV1AccSendToThreshold(t *testing.T) {
|
||||
attrs := &v1.AttrAddBalance{Tenant: "cgrates.org", Account: "testAccThreshold",
|
||||
BalanceId: utils.StringPointer("testAccSetBalance"),
|
||||
BalanceType: "*monetary", Value: 1.5}
|
||||
if err := accRpc.Call("ApierV1.SetBalance", attrs, &reply); err != nil {
|
||||
if err := accRpc.Call(utils.ApierV1SetBalance, attrs, &reply); err != nil {
|
||||
t.Error("Got error on ApierV1.SetBalance: ", err.Error())
|
||||
} else if reply != "OK" {
|
||||
t.Errorf("Calling ApierV1.SetBalance received: %s", reply)
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"time"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
v2 "github.com/cgrates/cgrates/apier/v2"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -48,6 +49,7 @@ var sTutTests = []func(t *testing.T){
|
||||
testTutRpcConn,
|
||||
testTutFromFolder,
|
||||
testTutGetCost,
|
||||
testTutAccounts,
|
||||
testTutStopEngine,
|
||||
}
|
||||
|
||||
@@ -238,6 +240,72 @@ func testTutGetCost(t *testing.T) {
|
||||
err.Error() != "SERVER_ERROR: UNAUTHORIZED_DESTINATION" {
|
||||
t.Error("Unexpected nil error received: ", err)
|
||||
}
|
||||
// Per call charges
|
||||
attrs = v1.AttrGetCost{
|
||||
Category: "call",
|
||||
Subject: "RPF_SPECIAL_BLC",
|
||||
Destination: "1002",
|
||||
AnswerTime: "*now",
|
||||
Usage: "5m",
|
||||
}
|
||||
if err := tutRpc.Call(utils.ApierV1GetCost, attrs, &rply); err != nil {
|
||||
t.Error("Unexpected nil error received: ", err.Error())
|
||||
} else if *rply.Cost != 0.1 {
|
||||
t.Errorf("Unexpected cost received: %f", *rply.Cost)
|
||||
}
|
||||
}
|
||||
|
||||
func testTutAccounts(t *testing.T) {
|
||||
// make sure Account was created
|
||||
var acnt *engine.Account
|
||||
if err := tutRpc.Call(utils.ApierV2GetAccount,
|
||||
&utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"},
|
||||
&acnt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(acnt.BalanceMap) != 4 ||
|
||||
len(acnt.BalanceMap[utils.MONETARY]) != 1 ||
|
||||
acnt.BalanceMap[utils.MONETARY][0].Value != 10 ||
|
||||
len(acnt.BalanceMap[utils.VOICE]) != 2 ||
|
||||
len(acnt.BalanceMap[utils.SMS]) != 1 ||
|
||||
acnt.BalanceMap[utils.SMS][0].Value != 100 ||
|
||||
len(acnt.BalanceMap[utils.DATA]) != 1 ||
|
||||
acnt.BalanceMap[utils.DATA][0].Value != 1024 ||
|
||||
len(acnt.ActionTriggers) != 2 ||
|
||||
acnt.Disabled {
|
||||
t.Errorf("received account: %s", utils.ToIJSON(acnt))
|
||||
}
|
||||
// test ActionTriggers
|
||||
attrs := &v1.AttrAddBalance{Tenant: "cgrates.org", Account: "1001",
|
||||
BalanceId: utils.StringPointer(utils.MetaDefault),
|
||||
BalanceType: utils.MONETARY, Value: 101}
|
||||
var reply string
|
||||
if err := tutRpc.Call(utils.ApierV1SetBalance, attrs, &reply); err != nil {
|
||||
t.Error("Got error on ApierV1.SetBalance: ", err.Error())
|
||||
}
|
||||
if err := tutRpc.Call(utils.ApierV2GetAccount,
|
||||
&utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"},
|
||||
&acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if !acnt.Disabled {
|
||||
t.Errorf("account: %s", utils.ToIJSON(acnt))
|
||||
}
|
||||
// enable the account again
|
||||
if err := tutRpc.Call(utils.ApierV2SetAccount,
|
||||
v2.AttrSetAccount{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "1001",
|
||||
Disabled: utils.BoolPointer(false),
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := tutRpc.Call(utils.ApierV2GetAccount,
|
||||
&utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"},
|
||||
&acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.Disabled {
|
||||
t.Errorf("account: %s", utils.ToIJSON(acnt))
|
||||
}
|
||||
}
|
||||
|
||||
func testTutStopEngine(t *testing.T) {
|
||||
|
||||
@@ -703,11 +703,14 @@ const (
|
||||
ApierV1GetEventCost = "ApierV1.GetEventCost"
|
||||
ApierV1LoadTariffPlanFromFolder = "ApierV1.LoadTariffPlanFromFolder"
|
||||
ApierV1GetCost = "ApierV1.GetCost"
|
||||
ApierV1SetBalance = "ApierV1.SetBalance"
|
||||
)
|
||||
|
||||
const (
|
||||
ApierV2LoadTariffPlanFromFolder = "ApierV2.LoadTariffPlanFromFolder"
|
||||
ApierV2GetCDRs = "ApierV2.GetCDRs"
|
||||
ApierV2GetAccount = "ApierV2.GetAccount"
|
||||
ApierV2SetAccount = "ApierV2.SetAccount"
|
||||
)
|
||||
|
||||
// SupplierS APIs
|
||||
|
||||
Reference in New Issue
Block a user