Skip to content

Commit

Permalink
Add tests for SSv1AuthorizeEvent with *sms & *data
Browse files Browse the repository at this point in the history
  • Loading branch information
arberkatellari authored and danbogos committed Nov 16, 2023
1 parent c6c4b17 commit 20f2f73
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/tariffplans/testit/ActionPlans.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#Id,ActionsId,TimingId,Weight
PACKAGE_1001,TOPUP_RST_MONETARY_10,*asap,10
PACKAGE_1001,ACTION_TOPUP_RESET_SMS,*asap,10
PACKAGE_1002,TOPUP_RST_DATA_100,*asap,10
1 change: 1 addition & 0 deletions data/tariffplans/testit/Actions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
TOPUP_RST_MONETARY_10,*topup_reset,,,,*monetary,,*any,,,*unlimited,,10,10,false,false,10
TOPUP_MONETARY_10,*topup,,,,*monetary,,*any,,,*unlimited,,10,10,false,false,10
TOPUP_RST_DATA_100,*topup_reset,,,,*data,,*any,,,*monthly,,4096,10,false,false,10
ACTION_TOPUP_RESET_SMS,*topup_reset,,,,*sms,,*any,,,*unlimited,,500,10,false,false,10
111 changes: 111 additions & 0 deletions general_tests/authorize_event_sms_data_it_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//go:build integration
// +build integration

/*
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 general_tests

import (
"path"
"testing"
"time"

"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)

func TestSSv1AuthorizeEventSMS(t *testing.T) {
var cfgDir string
switch *dbType {
case utils.MetaInternal:
cfgDir = "sessions_internal"
case utils.MetaMySQL:
cfgDir = "sessions_mysql"
case utils.MetaMongo:
cfgDir = "sessions_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
testEnv := TestEnvironment{
Name: "TestSSv1AuthorizeEventSMS",
ConfigPath: path.Join(*dataDir, "conf", "samples", cfgDir),
TpPath: path.Join(*dataDir, "tariffplans", "testit"),
}
client, _, shutdown, err := testEnv.Setup(t, *waitRater)
if err != nil {
t.Fatal(err)
}
defer shutdown()

t.Run("AuthorizeEventSMS", func(t *testing.T) {
args := &sessions.V1AuthorizeArgs{
GetMaxUsage: true,
GetAttributes: true,
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItAuthSMS",
Event: map[string]any{
utils.Tenant: "cgrates.org",
utils.ToR: utils.MetaSMS,
utils.OriginID: "TestSSv1It1SMS",
utils.AccountField: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2023, time.November, 16, 16, 60, 0, 0, time.UTC),
utils.Usage: 20,
},
},
}
var rply sessions.V1AuthorizeReply
if err := client.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil {
t.Fatal(err)
}
if rply.MaxUsage == nil || *rply.MaxUsage != 20 {
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
}
})

t.Run("AuthorizeEventData", func(t *testing.T) {
args := &sessions.V1AuthorizeArgs{
GetMaxUsage: true,
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItAuthData",
Event: map[string]any{
utils.Tenant: "cgrates.org",
utils.ToR: utils.MetaData,
utils.OriginID: "TestSSv1It1Data",
utils.AccountField: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2023, time.November, 16, 16, 60, 0, 0, time.UTC),
utils.Usage: 1024,
},
},
}
var rply sessions.V1AuthorizeReply
if err := client.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil {
t.Fatal(err)
}
if rply.MaxUsage == nil || *rply.MaxUsage != 1024 {
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
}
})

}

0 comments on commit 20f2f73

Please sign in to comment.