domain: add Storage ports (BYOS, Quota, LibraryPath) and QuotaChecker service
This commit is contained in:
@@ -1 +1,2 @@
|
||||
mod permission_service;
|
||||
mod quota_checker;
|
||||
|
||||
53
crates/domain/tests/services/quota_checker.rs
Normal file
53
crates/domain/tests/services/quota_checker.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use domain::entities::{QuotaDefinition, TimePeriod, UsageType};
|
||||
use domain::services::quota_checker::check_quota;
|
||||
use domain::value_objects::SystemId;
|
||||
|
||||
fn make_quota(limit: u64) -> QuotaDefinition {
|
||||
let mut q = QuotaDefinition::new(SystemId::new());
|
||||
q.add_rule(UsageType::StorageBytes, limit, TimePeriod::Monthly);
|
||||
q
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allows_within_limit() {
|
||||
let q = make_quota(1000);
|
||||
let r = check_quota(&q, UsageType::StorageBytes, 500, 400);
|
||||
assert!(r.allowed);
|
||||
assert!(!r.is_unlimited);
|
||||
assert_eq!(r.limit, 1000);
|
||||
assert_eq!(r.current_usage, 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_over_limit() {
|
||||
let q = make_quota(1000);
|
||||
let r = check_quota(&q, UsageType::StorageBytes, 800, 300);
|
||||
assert!(!r.allowed);
|
||||
assert_eq!(r.limit, 1000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unlimited_always_allowed() {
|
||||
let mut q = QuotaDefinition::new(SystemId::new());
|
||||
q.add_unlimited_rule(UsageType::StorageBytes);
|
||||
let r = check_quota(&q, UsageType::StorageBytes, u64::MAX, 1);
|
||||
assert!(r.allowed);
|
||||
assert!(r.is_unlimited);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unenforced_allows_all() {
|
||||
let mut q = make_quota(100);
|
||||
q.is_enforced = false;
|
||||
let r = check_quota(&q, UsageType::StorageBytes, 9999, 9999);
|
||||
assert!(r.allowed);
|
||||
assert!(r.is_unlimited);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_rule_allows() {
|
||||
let q = make_quota(1000); // rule for StorageBytes only
|
||||
let r = check_quota(&q, UsageType::ApiCalls, 9999, 9999);
|
||||
assert!(r.allowed);
|
||||
assert!(r.is_unlimited);
|
||||
}
|
||||
Reference in New Issue
Block a user