diff --git a/contracts/assetsup/src/lib.rs b/contracts/assetsup/src/lib.rs index eefca51..2c9b33a 100644 --- a/contracts/assetsup/src/lib.rs +++ b/contracts/assetsup/src/lib.rs @@ -5,6 +5,8 @@ pub(crate) mod asset; pub(crate) mod errors; pub(crate) mod types; +pub use types::*; + #[contracttype] #[derive(Clone, Debug, Eq, PartialEq)] pub enum DataKey { diff --git a/contracts/assetsup/src/tests/asset.rs b/contracts/assetsup/src/tests/asset.rs index d05be65..be80b71 100644 --- a/contracts/assetsup/src/tests/asset.rs +++ b/contracts/assetsup/src/tests/asset.rs @@ -34,7 +34,7 @@ fn test_register_and_get_asset_success() { let asset = Asset { id: id.clone(), name: name.clone(), - asset_type: AssetType::IT, + asset_type: AssetType::Digital, category: category.clone(), branch_id: 10, department_id: 20, @@ -54,7 +54,7 @@ fn test_register_and_get_asset_success() { assert_eq!(got.id, id); assert_eq!(got.name, name); - assert_eq!(got.asset_type, AssetType::IT); + assert_eq!(got.asset_type, AssetType::Digital); assert_eq!(got.category, category); assert_eq!(got.branch_id, 10); assert_eq!(got.department_id, 20); @@ -82,7 +82,7 @@ fn test_register_asset_duplicate() { let asset = Asset { id: id.clone(), name: name.clone(), - asset_type: AssetType::Furniture, + asset_type: AssetType::Physical, category: category.clone(), branch_id: 1, department_id: 2, diff --git a/contracts/assetsup/src/tests/mod.rs b/contracts/assetsup/src/tests/mod.rs index b9b57cb..201456d 100644 --- a/contracts/assetsup/src/tests/mod.rs +++ b/contracts/assetsup/src/tests/mod.rs @@ -1,2 +1,3 @@ mod asset; mod initialize; +mod types; diff --git a/contracts/assetsup/src/tests/types.rs b/contracts/assetsup/src/tests/types.rs new file mode 100644 index 0000000..d5402b3 --- /dev/null +++ b/contracts/assetsup/src/tests/types.rs @@ -0,0 +1,124 @@ +#![cfg(test)] + +use crate::types::*; + +#[test] +fn test_asset_type_variants() { + // Test that all AssetType variants can be created + let physical = AssetType::Physical; + let digital = AssetType::Digital; + + // Test equality + assert_eq!(physical, AssetType::Physical); + assert_eq!(digital, AssetType::Digital); + assert_ne!(physical, digital); + + // Test cloning + let physical_clone = physical.clone(); + assert_eq!(physical, physical_clone); +} + +#[test] +fn test_asset_status_variants() { + // Test that all AssetStatus variants can be created + let active = AssetStatus::Active; + let in_maintenance = AssetStatus::InMaintenance; + let disposed = AssetStatus::Disposed; + + // Test equality + assert_eq!(active, AssetStatus::Active); + assert_eq!(in_maintenance, AssetStatus::InMaintenance); + assert_eq!(disposed, AssetStatus::Disposed); + + // Test that they are different + assert_ne!(active, in_maintenance); + assert_ne!(active, disposed); + assert_ne!(in_maintenance, disposed); +} + +#[test] +fn test_action_type_variants() { + // Test that all ActionType variants can be created + let procured = ActionType::Procured; + let transferred = ActionType::Transferred; + let maintained = ActionType::Maintained; + let disposed = ActionType::Disposed; + let checked_in = ActionType::CheckedIn; + let checked_out = ActionType::CheckedOut; + + // Test equality + assert_eq!(procured, ActionType::Procured); + assert_eq!(transferred, ActionType::Transferred); + assert_eq!(maintained, ActionType::Maintained); + assert_eq!(disposed, ActionType::Disposed); + assert_eq!(checked_in, ActionType::CheckedIn); + assert_eq!(checked_out, ActionType::CheckedOut); + + // Test that they are different + assert_ne!(procured, transferred); + assert_ne!(checked_in, checked_out); +} + +#[test] +fn test_plan_type_variants() { + // Test that all PlanType variants can be created + let basic = PlanType::Basic; + let pro = PlanType::Pro; + let enterprise = PlanType::Enterprise; + + // Test equality + assert_eq!(basic, PlanType::Basic); + assert_eq!(pro, PlanType::Pro); + assert_eq!(enterprise, PlanType::Enterprise); + + // Test that they are different + assert_ne!(basic, pro); + assert_ne!(pro, enterprise); + assert_ne!(basic, enterprise); +} + +#[test] +fn test_subscription_status_variants() { + // Test that all SubscriptionStatus variants can be created + let active = SubscriptionStatus::Active; + let expired = SubscriptionStatus::Expired; + let cancelled = SubscriptionStatus::Cancelled; + + // Test equality + assert_eq!(active, SubscriptionStatus::Active); + assert_eq!(expired, SubscriptionStatus::Expired); + assert_eq!(cancelled, SubscriptionStatus::Cancelled); + + // Test that they are different + assert_ne!(active, expired); + assert_ne!(active, cancelled); + assert_ne!(expired, cancelled); +} + +#[test] +fn test_types_can_be_used_in_functions() { + // Test that types can be used as function parameters and return values + fn get_asset_type() -> AssetType { + AssetType::Physical + } + + fn process_action(action: ActionType) -> bool { + match action { + ActionType::Procured => true, + ActionType::Transferred => true, + ActionType::Maintained => true, + ActionType::Disposed => false, + ActionType::CheckedIn => true, + ActionType::CheckedOut => true, + } + } + + let asset_type = get_asset_type(); + assert_eq!(asset_type, AssetType::Physical); + + let result = process_action(ActionType::Procured); + assert!(result); + + let result = process_action(ActionType::Disposed); + assert!(!result); +} diff --git a/contracts/assetsup/src/types.rs b/contracts/assetsup/src/types.rs index 7339530..cd5ce28 100644 --- a/contracts/assetsup/src/types.rs +++ b/contracts/assetsup/src/types.rs @@ -1,22 +1,54 @@ #![allow(clippy::upper_case_acronyms)] use soroban_sdk::contracttype; +/// Represents the fundamental type of asset being managed +/// Distinguishes between physical and digital assets for different handling requirements #[contracttype] #[derive(Clone, Debug, Eq, PartialEq)] pub enum AssetType { - IT, - Furniture, - Vehicle, - RealEstate, - Machinery, - Other, + Physical, + Digital, } +/// Represents the current operational status of an asset +/// Used to track asset lifecycle and availability for use #[contracttype] #[derive(Clone, Debug, Eq, PartialEq)] pub enum AssetStatus { Active, - Maintenance, - Retired, + InMaintenance, Disposed, } + +/// Represents different types of actions that can be performed on assets +/// Used for audit trails and tracking asset lifecycle events +#[contracttype] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum ActionType { + Procured, + Transferred, + Maintained, + Disposed, + CheckedIn, + CheckedOut, +} + +/// Represents different subscription plan tiers +/// Used to determine feature access and usage limits +#[contracttype] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum PlanType { + Basic, + Pro, + Enterprise, +} + +/// Represents the current status of a subscription +/// Used to control access to platform features +#[contracttype] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum SubscriptionStatus { + Active, + Expired, + Cancelled, +}