mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 06:09:53 +05:00
Move cdrlog action tests from actions_test to actions_it_test.go to cover some cases
This commit is contained in:
committed by
Dan Christian Bogos
parent
a0254287ae
commit
c5d748db80
@@ -154,7 +154,6 @@ func cdrLogAction(acc *Account, sq *CDRStatsQueueTriggered, a *Action, acs Actio
|
||||
utils.COST: config.NewRSRParsersMustCompile(utils.DynamicDataPrefix+"ActionValue", true),
|
||||
}
|
||||
template := make(map[string]string)
|
||||
|
||||
// overwrite default template
|
||||
if a.ExtraParameters != "" {
|
||||
if err = json.Unmarshal([]byte(a.ExtraParameters), &template); err != nil {
|
||||
@@ -164,7 +163,6 @@ func cdrLogAction(acc *Account, sq *CDRStatsQueueTriggered, a *Action, acs Actio
|
||||
defaultTemplate[field] = config.NewRSRParsersMustCompile(rsr, true)
|
||||
}
|
||||
}
|
||||
|
||||
// set stored cdr values
|
||||
var cdrs []*CDR
|
||||
for _, action := range acs {
|
||||
|
||||
@@ -161,6 +161,79 @@ func TestActionsitSetCdrlogTopup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionsitCdrlogEmpty(t *testing.T) {
|
||||
var reply string
|
||||
attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "dan2904"}
|
||||
attrsAA := &utils.AttrSetActions{ActionsId: "ACTS_3", Actions: []*utils.TPAction{
|
||||
&utils.TPAction{Identifier: DEBIT, BalanceType: utils.MONETARY, DestinationIds: "RET",
|
||||
Units: "5", ExpiryTime: UNLIMITED, Weight: 20.0},
|
||||
&utils.TPAction{Identifier: CDRLOG},
|
||||
}}
|
||||
if err := actsLclRpc.Call("ApierV2.SetActions", attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
|
||||
t.Error("Got error on ApierV2.SetActions: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling ApierV2.SetActions received: %s", reply)
|
||||
}
|
||||
attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrsAA.ActionsId}
|
||||
if err := actsLclRpc.Call("ApierV1.ExecuteAction", attrsEA, &reply); err != nil {
|
||||
t.Error("Got error on ApierV1.ExecuteAction: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling ApierV1.ExecuteAction received: %s", reply)
|
||||
}
|
||||
var rcvedCdrs []*ExternalCDR
|
||||
if err := actsLclRpc.Call("ApierV2.GetCdrs", utils.RPCCDRsFilter{Sources: []string{CDRLOG},
|
||||
Accounts: []string{attrsSetAccount.Account}, RunIDs: []string{DEBIT}}, &rcvedCdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(rcvedCdrs) != 2 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(rcvedCdrs))
|
||||
} else {
|
||||
for _, cdr := range rcvedCdrs {
|
||||
if cdr.RunID != DEBIT {
|
||||
t.Errorf("Expecting : DEBIT, received: %+v", cdr.RunID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionsitCdrlogWithParams(t *testing.T) {
|
||||
var reply string
|
||||
attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "dan2904"}
|
||||
attrsAA := &utils.AttrSetActions{ActionsId: "ACTS_4",
|
||||
Actions: []*utils.TPAction{
|
||||
&utils.TPAction{Identifier: DEBIT, BalanceType: utils.MONETARY,
|
||||
DestinationIds: "RET", Units: "25", ExpiryTime: UNLIMITED, Weight: 20.0},
|
||||
&utils.TPAction{Identifier: CDRLOG,
|
||||
ExtraParameters: `{"RequestType":"*pseudoprepaid","Subject":"DifferentThanAccount", "ToR":"~ActionType:s/^\\*(.*)$/did_$1/"}`},
|
||||
&utils.TPAction{Identifier: DEBIT_RESET, BalanceType: utils.MONETARY,
|
||||
DestinationIds: "RET", Units: "25", ExpiryTime: UNLIMITED, Weight: 20.0},
|
||||
},
|
||||
}
|
||||
if err := actsLclRpc.Call("ApierV2.SetActions", attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
|
||||
t.Error("Got error on ApierV2.SetActions: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling ApierV2.SetActions received: %s", reply)
|
||||
}
|
||||
attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrsAA.ActionsId}
|
||||
if err := actsLclRpc.Call("ApierV1.ExecuteAction", attrsEA, &reply); err != nil {
|
||||
t.Error("Got error on ApierV1.ExecuteAction: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling ApierV1.ExecuteAction received: %s", reply)
|
||||
}
|
||||
var rcvedCdrs []*ExternalCDR
|
||||
if err := actsLclRpc.Call("ApierV2.GetCdrs", utils.RPCCDRsFilter{Sources: []string{CDRLOG},
|
||||
Accounts: []string{attrsSetAccount.Account}, RunIDs: []string{DEBIT}, RequestTypes: []string{"*pseudoprepaid"}}, &rcvedCdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(rcvedCdrs) != 1 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(rcvedCdrs))
|
||||
}
|
||||
if err := actsLclRpc.Call("ApierV2.GetCdrs", utils.RPCCDRsFilter{Sources: []string{CDRLOG},
|
||||
Accounts: []string{attrsSetAccount.Account}, RunIDs: []string{DEBIT_RESET}, RequestTypes: []string{"*pseudoprepaid"}}, &rcvedCdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(rcvedCdrs) != 1 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(rcvedCdrs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionsitStopCgrEngine(t *testing.T) {
|
||||
|
||||
if err := KillEngine(*waitRater); err != nil {
|
||||
|
||||
@@ -1467,94 +1467,6 @@ func TestTopupActionLoaded(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Disabled tests with cdrLogAction because it need a rpc connection
|
||||
func TestActionCdrlogEmpty(t *testing.T) {
|
||||
acnt := &Account{ID: "cgrates.org:dan2904"}
|
||||
cdrlog := &Action{
|
||||
ActionType: CDRLOG,
|
||||
}
|
||||
err := cdrLogAction(acnt, nil, cdrlog, Actions{
|
||||
&Action{
|
||||
ActionType: DEBIT,
|
||||
Balance: &BalanceFilter{Value: &utils.ValueFormula{Static: 25},
|
||||
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("RET")), Weight: utils.Float64Pointer(20)},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("Error performing cdrlog action: ", err)
|
||||
}
|
||||
cdrs := make([]*CDR, 0)
|
||||
json.Unmarshal([]byte(cdrlog.ExpirationString), &cdrs)
|
||||
if len(cdrs) != 1 || cdrs[0].Source != CDRLOG {
|
||||
t.Errorf("Wrong cdrlogs: %+v", cdrs[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionCdrlogWithParams(t *testing.T) {
|
||||
acnt := &Account{ID: "cgrates.org:dan2904"}
|
||||
cdrlog := &Action{
|
||||
ActionType: CDRLOG,
|
||||
ExtraParameters: `{"ReqType":"^*pseudoprepaid","Subject":"^rif", "TOR":"~action_type:s/^\\*(.*)$/did_$1/"}`,
|
||||
}
|
||||
err := cdrLogAction(acnt, nil, cdrlog, Actions{
|
||||
&Action{
|
||||
ActionType: DEBIT,
|
||||
Balance: &BalanceFilter{Value: &utils.ValueFormula{Static: 25},
|
||||
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("RET")), Weight: utils.Float64Pointer(20)},
|
||||
},
|
||||
&Action{
|
||||
ActionType: DEBIT_RESET,
|
||||
Balance: &BalanceFilter{Value: &utils.ValueFormula{Static: 25},
|
||||
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("RET")), Weight: utils.Float64Pointer(20)},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("Error performing cdrlog action: ", err)
|
||||
}
|
||||
cdrs := make([]*CDR, 0)
|
||||
json.Unmarshal([]byte(cdrlog.ExpirationString), &cdrs)
|
||||
if len(cdrs) != 2 ||
|
||||
cdrs[0].Subject != "rif" {
|
||||
t.Errorf("Wrong cdrlogs: %+v", cdrs[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionCdrLogParamsWithOverload(t *testing.T) {
|
||||
acnt := &Account{ID: "cgrates.org:dan2904"}
|
||||
cdrlog := &Action{
|
||||
ActionType: CDRLOG,
|
||||
ExtraParameters: `{"Subject":"^rif","Destination":"^1234","ToR":"~ActionTag:s/^at(.)$/0$1/","AccountID":"~AccountID:s/^\\*(.*)$/$1/"}`,
|
||||
}
|
||||
err := cdrLogAction(acnt, nil, cdrlog, Actions{
|
||||
&Action{
|
||||
ActionType: DEBIT,
|
||||
Balance: &BalanceFilter{Value: &utils.ValueFormula{Static: 25},
|
||||
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("RET")), Weight: utils.Float64Pointer(20)},
|
||||
},
|
||||
&Action{
|
||||
ActionType: DEBIT_RESET,
|
||||
Balance: &BalanceFilter{Value: &utils.ValueFormula{Static: 25},
|
||||
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("RET")), Weight: utils.Float64Pointer(20)},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("Error performing cdrlog action: ", err)
|
||||
}
|
||||
cdrs := make([]*CDR, 0)
|
||||
json.Unmarshal([]byte(cdrlog.ExpirationString), &cdrs)
|
||||
expectedExtraFields := map[string]string{
|
||||
"AccountID": "cgrates.org:dan2904",
|
||||
}
|
||||
if len(cdrs) != 2 ||
|
||||
cdrs[0].Subject != "rif" {
|
||||
t.Errorf("Wrong cdrlogs: %+v", cdrs[0])
|
||||
}
|
||||
if !reflect.DeepEqual(cdrs[0].ExtraFields, expectedExtraFields) {
|
||||
t.Errorf("Expecting extra fields: %+v, received: %+v", expectedExtraFields, cdrs[0].ExtraFields)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestActionSetDDestination(t *testing.T) {
|
||||
acc := &Account{BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{&Balance{DestinationIDs: utils.NewStringMap("*ddc_test")}}}}
|
||||
@@ -2391,70 +2303,6 @@ func TestActionExpNoExp(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestActionCdrlogBalanceValue(t *testing.T) {
|
||||
err := dm.DataDB().SetAccount(&Account{
|
||||
ID: "cgrates.org:bv",
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{&Balance{
|
||||
ID: "*default",
|
||||
Uuid: "25a02c82-f09f-4c6e-bacf-8ed4b076475a",
|
||||
Value: 10,
|
||||
}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("Error setting account: ", err)
|
||||
}
|
||||
at := &ActionTiming{
|
||||
accountIDs: utils.StringMap{"cgrates.org:bv": true},
|
||||
Timing: &RateInterval{},
|
||||
actions: []*Action{
|
||||
&Action{
|
||||
Id: "RECUR_FOR_V3HSILLMILLD1G",
|
||||
ActionType: TOPUP,
|
||||
Balance: &BalanceFilter{
|
||||
ID: utils.StringPointer("*default"),
|
||||
Uuid: utils.StringPointer("25a02c82-f09f-4c6e-bacf-8ed4b076475a"),
|
||||
Value: &utils.ValueFormula{Static: 1.1},
|
||||
Type: utils.StringPointer(utils.MONETARY),
|
||||
},
|
||||
},
|
||||
&Action{
|
||||
Id: "RECUR_FOR_V3HSILLMILLD5G",
|
||||
ActionType: DEBIT,
|
||||
Balance: &BalanceFilter{
|
||||
ID: utils.StringPointer("*default"),
|
||||
Uuid: utils.StringPointer("25a02c82-f09f-4c6e-bacf-8ed4b076475a"),
|
||||
Value: &utils.ValueFormula{Static: 2.1},
|
||||
Type: utils.StringPointer(utils.MONETARY),
|
||||
},
|
||||
},
|
||||
&Action{
|
||||
Id: "c",
|
||||
ActionType: CDRLOG,
|
||||
ExtraParameters: `{"BalanceID":"BalanceID","BalanceUUID":"BalanceUUID","ActionID":"ActionID","BalanceValue":"BalanceValue"}`,
|
||||
},
|
||||
},
|
||||
}
|
||||
err = at.Execute(nil, nil)
|
||||
acc, err := dm.DataDB().GetAccount("cgrates.org:bv")
|
||||
if err != nil || acc == nil {
|
||||
t.Error("Error getting account: ", acc, err)
|
||||
}
|
||||
if acc.BalanceMap[utils.MONETARY][0].Value != 9 {
|
||||
t.Errorf("Transaction didn't work: %v", acc.BalanceMap[utils.MONETARY][0].Value)
|
||||
}
|
||||
cdrs := make([]*CDR, 0)
|
||||
json.Unmarshal([]byte(at.actions[2].ExpirationString), &cdrs)
|
||||
if len(cdrs) != 2 ||
|
||||
cdrs[0].ExtraFields["BalanceValue"] != "11.1" ||
|
||||
cdrs[1].ExtraFields["BalanceValue"] != "9" {
|
||||
t.Errorf("Wrong cdrlogs: %s", utils.ToIJSON(cdrs))
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestActionTopUpZeroNegative(t *testing.T) {
|
||||
account := &Account{
|
||||
ID: "cgrates.org:zeroNegative",
|
||||
|
||||
Reference in New Issue
Block a user