|
2 | 2 |
|
3 | 3 | extern crate std; |
4 | 4 |
|
5 | | -use soroban_sdk::{Address, BytesN, Env, String, testutils::Address as _}; |
| 5 | +use soroban_sdk::testutils::{Address as _, BytesN as _}; |
| 6 | + |
| 7 | +use soroban_sdk::{Address, BytesN, Env, String}; |
6 | 8 |
|
7 | 9 | use crate::{ |
8 | 10 | asset::Asset, |
@@ -101,3 +103,40 @@ fn test_register_asset_duplicate() { |
101 | 103 | // Second registration with same ID should panic (Err propagated) |
102 | 104 | client.register_asset(&asset); |
103 | 105 | } |
| 106 | + |
| 107 | +#[test] |
| 108 | +fn test_update_status_creates_audit_log() { |
| 109 | + let (env, client, _admin) = setup_test_environment(); |
| 110 | + let owner = Address::generate(&env); |
| 111 | + |
| 112 | + // Create and register asset first |
| 113 | + let asset = Asset { |
| 114 | + id: BytesN::random(&env), |
| 115 | + name: String::from_str(&env, "Test Asset"), |
| 116 | + asset_type: AssetType::Physical, |
| 117 | + category: String::from_str(&env, "Test Category"), |
| 118 | + branch_id: 1, |
| 119 | + department_id: 1, |
| 120 | + status: AssetStatus::Active, |
| 121 | + purchase_date: 12345, |
| 122 | + purchase_cost: 1000, |
| 123 | + current_value: 900, |
| 124 | + warranty_expiry: 67890, |
| 125 | + stellar_token_id: BytesN::random(&env), |
| 126 | + owner: owner.clone(), |
| 127 | + }; |
| 128 | + |
| 129 | + client.register_asset(&asset); |
| 130 | + |
| 131 | + // Update to Maintained status |
| 132 | + client.update_asset_status(&asset.id, &AssetStatus::InMaintenance); |
| 133 | + |
| 134 | + // Verify audit logs |
| 135 | + let logs = client.get_asset_audit_logs(&asset.id); |
| 136 | + assert_eq!(logs.len(), 2); // Procurement + Maintenance |
| 137 | + assert_eq!( |
| 138 | + logs.get(1).unwrap().action, |
| 139 | + String::from_str(&env, "IN_MAINTENANCE") |
| 140 | + ); |
| 141 | + assert_eq!(logs.get(1).unwrap().actor, owner); |
| 142 | +} |
0 commit comments