mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
tested negative debit
This commit is contained in:
@@ -239,7 +239,7 @@ func TestGetCostWithVolumeDiscount(t *testing.T) {
|
||||
vd1 := &VolumeDiscount{100, 10}
|
||||
vd2 := &VolumeDiscount{500, 20}
|
||||
seara := &TariffPlan{Id: "seara", SmsCredit: 100, VolumeDiscountThresholds: []*VolumeDiscount{vd1, vd2}}
|
||||
rifsBudget := &UserBudget{Id: "other", Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10, VolumeDiscountSeconds: 105}
|
||||
rifsBudget := &UserBudget{Id: "rif", Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10, VolumeDiscountSeconds: 105}
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0723", TimeStart: t1, TimeEnd: t2, storageGetter: getter, userBudget: rifsBudget}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package timespans
|
||||
|
||||
import (
|
||||
"log"
|
||||
// "log"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -139,7 +139,7 @@ Returns user's avaliable minutes for the specified destination
|
||||
*/
|
||||
func (ub *UserBudget) getSecondsForPrefix(sg StorageGetter, prefix string) (seconds float64, bucketList bucketsorter) {
|
||||
if len(ub.MinuteBuckets) == 0 {
|
||||
log.Print("There are no minute buckets to check for user: ", ub.Id)
|
||||
// log.Print("There are no minute buckets to check for user: ", ub.Id)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +148,18 @@ func TestDebitMoreMoneyBudget(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebitNegativeMoneyBudget(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
result := rifsBudget.debitMoneyBudget(getter, -15)
|
||||
if rifsBudget.Credit != 36 || result != rifsBudget.Credit {
|
||||
t.Errorf("Expected %v was %v", 36, rifsBudget.Credit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebitMinuteBudget(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
@@ -236,6 +248,32 @@ func TestDebitPriceMoreMinuteBudget(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebitPriceNegativeMinuteBudget(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 1.0, DestinationId: "retea"}
|
||||
rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBudget.debitMinutesBudget(getter, -15, "0723")
|
||||
if b2.Seconds != 115 || b1.Seconds != 10 || err != nil || rifsBudget.Credit != 36 {
|
||||
t.Log(b1, b2, err)
|
||||
t.Errorf("Expected %v was %v", 36, rifsBudget.Credit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebitNegativeMinuteBudget(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBudget.debitMinutesBudget(getter, -15, "0723")
|
||||
if b2.Seconds != 115 || b1.Seconds != 10 || err != nil || rifsBudget.Credit != 21 {
|
||||
t.Log(b1, b2, err)
|
||||
t.Errorf("Expected %v was %v", 21, rifsBudget.Credit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebitSMSBudget(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
@@ -272,6 +310,18 @@ func TestDebitMoreSMSBudget(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebitNegativeSMSBudget(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, SmsCredit: 100, ResetDayOfTheMonth: 10}
|
||||
result, err := rifsBudget.debitSMSBuget(getter, -15)
|
||||
if rifsBudget.SmsCredit != 115 || result != rifsBudget.SmsCredit || err != nil {
|
||||
t.Errorf("Expected %v was %v", 115, rifsBudget.SmsCredit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResetUserBudget(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
|
||||
Reference in New Issue
Block a user