mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Revise balance blockers
This commit is contained in:
committed by
Dan Christian Bogos
parent
88ff4d9c4f
commit
7add01320e
@@ -412,6 +412,9 @@ func (acc *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun bo
|
||||
// check for blocker
|
||||
if balance.Blocker {
|
||||
if cd.GetDuration() != 0 {
|
||||
if !dryRun {
|
||||
return nil, utils.ErrInsufficientCreditBalanceBlocker
|
||||
}
|
||||
return
|
||||
}
|
||||
goto COMMIT // don't go to next balances
|
||||
@@ -448,6 +451,9 @@ func (acc *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun bo
|
||||
// check for blocker
|
||||
if balance.Blocker {
|
||||
if cd.GetDuration() != 0 {
|
||||
if !dryRun {
|
||||
return nil, utils.ErrInsufficientCreditBalanceBlocker
|
||||
}
|
||||
return
|
||||
}
|
||||
goto COMMIT // don't go to next balances
|
||||
|
||||
1518
general_tests/balance_blocker_it_test.go
Normal file
1518
general_tests/balance_blocker_it_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -123,7 +123,7 @@ cgrates.org,call,1001,,RP_ANY,`,
|
||||
}
|
||||
})
|
||||
|
||||
// Attempt to debit 0.7, but due to the blocker and the empty balance, the final cost should be 0.
|
||||
// Attempt to debit 0.7, but due to the blocker and the empty balance, the final cost should be -1.
|
||||
t.Run("ProcessCDR2", func(t *testing.T) {
|
||||
var reply string
|
||||
if err := client.Call(utils.CDRsV1ProcessEvent,
|
||||
@@ -163,28 +163,17 @@ cgrates.org,call,1001,,RP_ANY,`,
|
||||
if len(cdrs) != 2 {
|
||||
t.Fatalf("expected to receive 2 CDRs: %v", utils.ToJSON(cdrs))
|
||||
}
|
||||
if cdrs[0].Cost != -1 {
|
||||
t.Fatalf("expected cost to be -1, received <%v>", utils.ToJSON(cdrs[0]))
|
||||
}
|
||||
cost := 0.0
|
||||
if cdrs[0].CostDetails.Cost != nil {
|
||||
cost = *cdrs[0].CostDetails.Cost
|
||||
}
|
||||
if cost != 1 {
|
||||
t.Fatalf("cdrs[0].CostDetails.Cost = %v, want %v", cost, 1)
|
||||
}
|
||||
balanceSummaries := cdrs[0].CostDetails.AccountSummary.BalanceSummaries
|
||||
if len(balanceSummaries) != 1 {
|
||||
t.Fatalf("expected only 1 balance summary inside first CDR, got %s", utils.ToJSON(balanceSummaries))
|
||||
}
|
||||
if balanceSummaries[0].Value != 0 {
|
||||
t.Errorf("expected balance to be empty, got %v", balanceSummaries[0].Value)
|
||||
}
|
||||
|
||||
if cdrs[1].CostDetails.Cost != nil {
|
||||
cost = *cdrs[1].CostDetails.Cost
|
||||
}
|
||||
if cost != 0 {
|
||||
t.Errorf("cdrs[1].CostDetails.Cost = %v, want %v", cost, 0)
|
||||
if cost != 0.7 {
|
||||
t.Errorf("cdrs[1].CostDetails.Cost = %v, want %v", cost, 0.7)
|
||||
}
|
||||
balanceSummaries = cdrs[1].CostDetails.AccountSummary.BalanceSummaries
|
||||
balanceSummaries := cdrs[1].CostDetails.AccountSummary.BalanceSummaries
|
||||
if len(balanceSummaries) != 1 {
|
||||
t.Errorf("expected only 1 balance summary inside second CDR, got %s", utils.ToJSON(balanceSummaries))
|
||||
}
|
||||
|
||||
@@ -27,51 +27,52 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoMoreData = errors.New("NO_MORE_DATA")
|
||||
ErrNotImplemented = errors.New("NOT_IMPLEMENTED")
|
||||
ErrNotFound = errors.New("NOT_FOUND")
|
||||
ErrTimedOut = errors.New("TIMED_OUT")
|
||||
ErrServerError = errors.New("SERVER_ERROR")
|
||||
ErrMaxRecursionDepth = errors.New("MAX_RECURSION_DEPTH")
|
||||
ErrMandatoryIeMissing = errors.New("MANDATORY_IE_MISSING")
|
||||
ErrExists = errors.New("EXISTS")
|
||||
ErrBrokenReference = errors.New("BROKEN_REFERENCE")
|
||||
ErrParserError = errors.New("PARSER_ERROR")
|
||||
ErrInvalidPath = errors.New("INVALID_PATH")
|
||||
ErrInvalidKey = errors.New("INVALID_KEY")
|
||||
ErrUnauthorizedDestination = errors.New("UNAUTHORIZED_DESTINATION")
|
||||
ErrRatingPlanNotFound = errors.New("RATING_PLAN_NOT_FOUND")
|
||||
ErrAccountNotFound = errors.New("ACCOUNT_NOT_FOUND")
|
||||
ErrAccountDisabled = errors.New("ACCOUNT_DISABLED")
|
||||
ErrInsufficientCredit = errors.New("INSUFFICIENT_CREDIT")
|
||||
ErrNotConvertible = errors.New("NOT_CONVERTIBLE")
|
||||
ErrResourceUnavailable = errors.New("RESOURCE_UNAVAILABLE")
|
||||
ErrResourceUnauthorized = errors.New("RESOURCE_UNAUTHORIZED")
|
||||
ErrNoActiveSession = errors.New("NO_ACTIVE_SESSION")
|
||||
ErrPartiallyExecuted = errors.New("PARTIALLY_EXECUTED")
|
||||
ErrMaxUsageExceeded = errors.New("MAX_USAGE_EXCEEDED")
|
||||
ErrFilterNotPassingNoCaps = errors.New("filter not passing")
|
||||
ErrNotConvertibleNoCaps = errors.New("not convertible")
|
||||
ErrMandatoryIeMissingNoCaps = errors.New("mandatory information missing")
|
||||
ErrUnauthorizedApi = errors.New("UNAUTHORIZED_API")
|
||||
ErrUnknownApiKey = errors.New("UNKNOWN_API_KEY")
|
||||
ErrReqUnsynchronized = errors.New("REQ_UNSYNCHRONIZED")
|
||||
ErrUnsupporteServiceMethod = errors.New("UNSUPPORTED_SERVICE_METHOD")
|
||||
ErrDisconnected = errors.New("DISCONNECTED")
|
||||
ErrReplyTimeout = errors.New("REPLY_TIMEOUT")
|
||||
ErrSessionNotFound = errors.New("SESSION_NOT_FOUND")
|
||||
ErrJsonIncompleteComment = errors.New("JSON_INCOMPLETE_COMMENT")
|
||||
ErrNotEnoughParameters = errors.New("NotEnoughParameters")
|
||||
ErrNotConnected = errors.New("NOT_CONNECTED")
|
||||
RalsErrorPrfx = "RALS_ERROR"
|
||||
DispatcherErrorPrefix = "DISPATCHER_ERROR"
|
||||
ErrUnsupportedFormat = errors.New("UNSUPPORTED_FORMAT")
|
||||
ErrNoDatabaseConn = errors.New("NO_DATA_BASE_CONNECTION")
|
||||
ErrMaxIncrementsExceeded = errors.New("MAX_INCREMENTS_EXCEEDED")
|
||||
ErrIndexOutOfBounds = errors.New("INDEX_OUT_OF_BOUNDS")
|
||||
ErrWrongPath = errors.New("WRONG_PATH")
|
||||
ErrServiceAlreadyRunning = fmt.Errorf("service already running")
|
||||
ErrCombimedNotFound = errors.New("COMBIMED_NOT_FOUND")
|
||||
ErrNoMoreData = errors.New("NO_MORE_DATA")
|
||||
ErrNotImplemented = errors.New("NOT_IMPLEMENTED")
|
||||
ErrNotFound = errors.New("NOT_FOUND")
|
||||
ErrTimedOut = errors.New("TIMED_OUT")
|
||||
ErrServerError = errors.New("SERVER_ERROR")
|
||||
ErrMaxRecursionDepth = errors.New("MAX_RECURSION_DEPTH")
|
||||
ErrMandatoryIeMissing = errors.New("MANDATORY_IE_MISSING")
|
||||
ErrExists = errors.New("EXISTS")
|
||||
ErrBrokenReference = errors.New("BROKEN_REFERENCE")
|
||||
ErrParserError = errors.New("PARSER_ERROR")
|
||||
ErrInvalidPath = errors.New("INVALID_PATH")
|
||||
ErrInvalidKey = errors.New("INVALID_KEY")
|
||||
ErrUnauthorizedDestination = errors.New("UNAUTHORIZED_DESTINATION")
|
||||
ErrRatingPlanNotFound = errors.New("RATING_PLAN_NOT_FOUND")
|
||||
ErrAccountNotFound = errors.New("ACCOUNT_NOT_FOUND")
|
||||
ErrAccountDisabled = errors.New("ACCOUNT_DISABLED")
|
||||
ErrInsufficientCredit = errors.New("INSUFFICIENT_CREDIT")
|
||||
ErrNotConvertible = errors.New("NOT_CONVERTIBLE")
|
||||
ErrResourceUnavailable = errors.New("RESOURCE_UNAVAILABLE")
|
||||
ErrResourceUnauthorized = errors.New("RESOURCE_UNAUTHORIZED")
|
||||
ErrNoActiveSession = errors.New("NO_ACTIVE_SESSION")
|
||||
ErrPartiallyExecuted = errors.New("PARTIALLY_EXECUTED")
|
||||
ErrMaxUsageExceeded = errors.New("MAX_USAGE_EXCEEDED")
|
||||
ErrFilterNotPassingNoCaps = errors.New("filter not passing")
|
||||
ErrNotConvertibleNoCaps = errors.New("not convertible")
|
||||
ErrMandatoryIeMissingNoCaps = errors.New("mandatory information missing")
|
||||
ErrUnauthorizedApi = errors.New("UNAUTHORIZED_API")
|
||||
ErrUnknownApiKey = errors.New("UNKNOWN_API_KEY")
|
||||
ErrReqUnsynchronized = errors.New("REQ_UNSYNCHRONIZED")
|
||||
ErrUnsupporteServiceMethod = errors.New("UNSUPPORTED_SERVICE_METHOD")
|
||||
ErrDisconnected = errors.New("DISCONNECTED")
|
||||
ErrReplyTimeout = errors.New("REPLY_TIMEOUT")
|
||||
ErrSessionNotFound = errors.New("SESSION_NOT_FOUND")
|
||||
ErrJsonIncompleteComment = errors.New("JSON_INCOMPLETE_COMMENT")
|
||||
ErrNotEnoughParameters = errors.New("NotEnoughParameters")
|
||||
ErrNotConnected = errors.New("NOT_CONNECTED")
|
||||
RalsErrorPrfx = "RALS_ERROR"
|
||||
DispatcherErrorPrefix = "DISPATCHER_ERROR"
|
||||
ErrUnsupportedFormat = errors.New("UNSUPPORTED_FORMAT")
|
||||
ErrNoDatabaseConn = errors.New("NO_DATA_BASE_CONNECTION")
|
||||
ErrMaxIncrementsExceeded = errors.New("MAX_INCREMENTS_EXCEEDED")
|
||||
ErrIndexOutOfBounds = errors.New("INDEX_OUT_OF_BOUNDS")
|
||||
ErrWrongPath = errors.New("WRONG_PATH")
|
||||
ErrServiceAlreadyRunning = fmt.Errorf("service already running")
|
||||
ErrCombimedNotFound = errors.New("COMBIMED_NOT_FOUND")
|
||||
ErrInsufficientCreditBalanceBlocker = errors.New("INSUFFICIENT_CREDIT_BALANCE_BLOCKER")
|
||||
|
||||
ErrMap = map[string]error{
|
||||
ErrNoMoreData.Error(): ErrNoMoreData,
|
||||
|
||||
Reference in New Issue
Block a user