mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 19:12:54 +00:00
- Add credit_management_tests.rs with tests for SubscriberAccount, UsageEvent, UsageType, AccountStatus, and integer arithmetic operations - Add error_tests.rs with tests for ChargingError Display implementation, cloning, and log_error function - Add rating_billing_tests.rs with tests for ChargingRule variants, as_str conversion, billing period parsing, timestamp filtering, and cost calculations - Add validation_tests.rs with tests for validate_bytes, validate
52 lines
2.2 KiB
Rust
52 lines
2.2 KiB
Rust
use charging_engine::errors::{ChargingError, log_error};
|
|
|
|
#[test]
|
|
fn test_charging_error_display() {
|
|
let err = ChargingError::RedisConnection("connection failed".to_string());
|
|
assert_eq!(err.to_string(), "Redis connection error: connection failed");
|
|
|
|
let err = ChargingError::RedisOperation("operation failed".to_string());
|
|
assert_eq!(err.to_string(), "Redis operation error: operation failed");
|
|
|
|
let err = ChargingError::DatabaseError("query failed".to_string());
|
|
assert_eq!(err.to_string(), "Database error: query failed");
|
|
|
|
let err = ChargingError::SubscriberNotFound("12345".to_string());
|
|
assert_eq!(err.to_string(), "Subscriber not found: 12345");
|
|
|
|
let err = ChargingError::RatingPlanNotFound("basic".to_string());
|
|
assert_eq!(err.to_string(), "Rating plan not found: basic");
|
|
|
|
let err = ChargingError::InsufficientCredit { available: 100, requested: 200 };
|
|
assert_eq!(err.to_string(), "Insufficient credit: available=100, requested=200");
|
|
|
|
let err = ChargingError::UsageBlocked("user blocked".to_string());
|
|
assert_eq!(err.to_string(), "Usage blocked: user blocked");
|
|
|
|
let err = ChargingError::InvalidInput("bad input".to_string());
|
|
assert_eq!(err.to_string(), "Invalid input: bad input");
|
|
|
|
let err = ChargingError::SerializationError("json error".to_string());
|
|
assert_eq!(err.to_string(), "Serialization error: json error");
|
|
|
|
let err = ChargingError::InternalError("internal error".to_string());
|
|
assert_eq!(err.to_string(), "Internal error: internal error");
|
|
}
|
|
|
|
#[test]
|
|
fn test_charging_error_clone() {
|
|
let err1 = ChargingError::RedisConnection("test".to_string());
|
|
let err2 = err1.clone();
|
|
assert_eq!(err1.to_string(), err2.to_string());
|
|
}
|
|
|
|
#[test]
|
|
fn test_log_error() {
|
|
// This test just ensures log_error doesn't panic
|
|
log_error(&ChargingError::RedisConnection("test".to_string()));
|
|
log_error(&ChargingError::DatabaseError("test".to_string()));
|
|
log_error(&ChargingError::SubscriberNotFound("123".to_string()));
|
|
log_error(&ChargingError::InsufficientCredit { available: 100, requested: 200 });
|
|
log_error(&ChargingError::InvalidInput("test".to_string()));
|
|
}
|