Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/connectors/user_service/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::connector::UserServiceConnector;
use super::types::{
CategoryInfo, PlanDefinition, ProductInfo, StackResponse, UserPlanInfo, UserProfile,
};
use super::utils::is_plan_upgrade;
use super::utils::is_plan_higher_tier;

/// HTTP-based User Service client
pub struct UserServiceClient {
Expand Down Expand Up @@ -260,7 +260,7 @@ impl UserServiceConnector for UserServiceClient {
return user_plan == required_plan_name;
}
user_plan == required_plan_name
|| is_plan_upgrade(&user_plan, required_plan_name)
|| is_plan_higher_tier(&user_plan, required_plan_name)
})
.map_err(|_| ConnectorError::InvalidResponse(text))
}
Expand Down
18 changes: 9 additions & 9 deletions src/connectors/user_service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde_json::json;
use uuid::Uuid;

use super::mock;
use super::utils::is_plan_upgrade;
use super::utils::is_plan_higher_tier;
use super::{CategoryInfo, ProductInfo, UserProfile, UserServiceConnector};

/// Test that get_user_profile returns user with products list
Expand Down Expand Up @@ -221,24 +221,24 @@ async fn test_mock_list_stacks() {

/// Test plan hierarchy comparison
#[test]
fn test_is_plan_upgrade_hierarchy() {
fn test_is_plan_higher_tier_hierarchy() {
// Enterprise user can access professional tier
assert!(is_plan_upgrade("enterprise", "professional"));
assert!(is_plan_higher_tier("enterprise", "professional"));

// Enterprise user can access basic tier
assert!(is_plan_upgrade("enterprise", "basic"));
assert!(is_plan_higher_tier("enterprise", "basic"));

// Professional user can access basic tier
assert!(is_plan_upgrade("professional", "basic"));
assert!(is_plan_higher_tier("professional", "basic"));

// Basic user cannot access professional
assert!(!is_plan_upgrade("basic", "professional"));
assert!(!is_plan_higher_tier("basic", "professional"));

// Basic user cannot access enterprise
assert!(!is_plan_upgrade("basic", "enterprise"));
assert!(!is_plan_higher_tier("basic", "enterprise"));

// Same plan should not be considered upgrade
assert!(!is_plan_upgrade("professional", "professional"));
// Same plan should not be considered higher tier
assert!(!is_plan_higher_tier("professional", "professional"));
}

/// Test UserProfile deserialization with all fields
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/user_service/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Helper function to determine if a plan tier can access a required plan
/// Basic idea: enterprise >= professional >= basic
pub(crate) fn is_plan_upgrade(user_plan: &str, required_plan: &str) -> bool {
pub(crate) fn is_plan_higher_tier(user_plan: &str, required_plan: &str) -> bool {
let plan_hierarchy = vec!["basic", "professional", "enterprise"];

let user_level = plan_hierarchy
Expand Down