diff --git a/nym-api/tests/public-api-tests.rs b/nym-api/tests/public-api-tests.rs index 96808d66b1..f6c0030535 100644 --- a/nym-api/tests/public-api-tests.rs +++ b/nym-api/tests/public-api-tests.rs @@ -1,3 +1,6 @@ +#[path = "public-api/utils.rs"] +mod utils; + #[path = "public-api/api_status.rs"] mod api_status; diff --git a/nym-api/tests/public-api/api_status.rs b/nym-api/tests/public-api/api_status.rs index 8d99763590..a7607832f8 100644 --- a/nym-api/tests/public-api/api_status.rs +++ b/nym-api/tests/public-api/api_status.rs @@ -1,5 +1,5 @@ mod utils; -use utils::{base_url, test_client, validate_json_response}; +use crate::utils::{base_url, test_client, validate_json_response}; #[tokio::test] async fn test_health() { diff --git a/nym-api/tests/public-api/circulating_supply.rs b/nym-api/tests/public-api/circulating_supply.rs index 31c4175a70..4190c2556a 100644 --- a/nym-api/tests/public-api/circulating_supply.rs +++ b/nym-api/tests/public-api/circulating_supply.rs @@ -1,5 +1,5 @@ mod utils; -use utils::{base_url, test_client, validate_json_response}; +use crate::utils::{base_url, test_client, validate_json_response}; #[tokio::test] async fn test_get_circulating_supply() { diff --git a/nym-api/tests/public-api/contract_cache.rs b/nym-api/tests/public-api/contract_cache.rs index cf08733e99..b67d598c81 100644 --- a/nym-api/tests/public-api/contract_cache.rs +++ b/nym-api/tests/public-api/contract_cache.rs @@ -1,5 +1,5 @@ mod utils; -use utils::{base_url, test_client, validate_json_response}; +use crate::utils::{base_url, test_client, validate_json_response}; #[tokio::test] async fn test_get_current_epoch() { diff --git a/nym-api/tests/public-api/network.rs b/nym-api/tests/public-api/network.rs index 3e2fd7be24..4503a96f64 100644 --- a/nym-api/tests/public-api/network.rs +++ b/nym-api/tests/public-api/network.rs @@ -1,5 +1,5 @@ mod utils; -use utils::{base_url, test_client, validate_json_response}; +use crate::utils::{base_url, test_client, validate_json_response}; #[tokio::test] async fn test_get_chain_status() { diff --git a/nym-api/tests/public-api/nym_nodes.rs b/nym-api/tests/public-api/nym_nodes.rs index b9df30e903..740adf9367 100644 --- a/nym-api/tests/public-api/nym_nodes.rs +++ b/nym-api/tests/public-api/nym_nodes.rs @@ -1,6 +1,6 @@ mod utils; +use crate::utils::{base_url, get_any_node_id, test_client, validate_json_response}; use chrono::Utc; -use utils::{base_url, get_any_node_id, test_client, validate_json_response}; #[tokio::test] async fn test_get_bonded_nodes() { @@ -15,7 +15,7 @@ async fn test_get_bonded_nodes() { assert!(data.is_array(), "Expected 'data' to be an array"); assert!( - data.as_array().unwrap().len() > 0, + !data.as_array().unwrap().is_empty(), "Expected at least one bonded node" ); } @@ -33,7 +33,7 @@ async fn test_get_described_nodes() { assert!(data.is_array(), "Expected 'data' to be an array"); assert!( - data.as_array().unwrap().len() > 0, + !data.as_array().unwrap().is_empty(), "Expected at least one node to appear" ); } @@ -126,7 +126,7 @@ async fn test_get_performance_history() { assert!(data.is_array(), "Expected 'history.data' to be an array"); assert!( - data.as_array().unwrap().len() > 0, + !data.as_array().unwrap().is_empty(), "Expected at least one performance history entry" ); } @@ -168,7 +168,7 @@ async fn test_get_uptime_history() { assert!(data.is_array(), "Expected 'history.data' to be an array"); assert!( - data.as_array().unwrap().len() > 0, + !data.as_array().unwrap().is_empty(), "Expected at least one performance history entry" ); } diff --git a/nym-api/tests/public-api/status.rs b/nym-api/tests/public-api/status.rs index 84882223f3..09f826f1a5 100644 --- a/nym-api/tests/public-api/status.rs +++ b/nym-api/tests/public-api/status.rs @@ -1,6 +1,6 @@ mod utils; +use crate::utils::{base_url, test_client}; use serde_json::Value; -use utils::{base_url, test_client}; #[tokio::test] async fn test_get_config_score_details() { @@ -16,7 +16,10 @@ async fn test_get_config_score_details() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let version_history = json .get("version_history") diff --git a/nym-api/tests/public-api/unstable_nym_nodes.rs b/nym-api/tests/public-api/unstable_nym_nodes.rs index b46b420c7b..b3d6705672 100644 --- a/nym-api/tests/public-api/unstable_nym_nodes.rs +++ b/nym-api/tests/public-api/unstable_nym_nodes.rs @@ -1,6 +1,6 @@ mod utils; +use crate::utils::{base_url, test_client}; use serde_json::Value; -use utils::{base_url, test_client}; #[tokio::test] async fn test_get_skimmed_nodes_active() { @@ -16,7 +16,10 @@ async fn test_get_skimmed_nodes_active() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let data = json .get("nodes") .and_then(|r| r.get("data")) @@ -24,7 +27,7 @@ async fn test_get_skimmed_nodes_active() { assert!(data.is_array(), "Expected 'data' to be an array"); assert!( - data.as_array().unwrap().len() > 0, + !data.as_array().unwrap().is_empty(), "Expected at least one node to appear" ); } @@ -46,7 +49,10 @@ async fn test_get_skimmed_active_mixnodes() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let current_epoch_id = json .get("status") .and_then(|r| r.get("fresh")) @@ -77,7 +83,10 @@ async fn test_get_skimmed_all_mixnodes() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let current_epoch_id = json .get("status") .and_then(|r| r.get("fresh")) @@ -111,7 +120,10 @@ async fn test_get_skimmed_active_exit_gateways() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let current_epoch_id = json .get("status") .and_then(|r| r.get("fresh")) @@ -145,7 +157,10 @@ async fn test_get_skimmed_all_exit_gateways() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let current_epoch_id = json .get("status") .and_then(|r| r.get("fresh")) @@ -179,7 +194,10 @@ async fn test_get_skimmed_active_entry_gateways() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let current_epoch_id = json .get("status") .and_then(|r| r.get("fresh")) @@ -213,7 +231,10 @@ async fn test_get_skimmed_all_entry_gateways() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let current_epoch_id = json .get("status") .and_then(|r| r.get("fresh")) diff --git a/nym-api/tests/public-api/unstable_status.rs b/nym-api/tests/public-api/unstable_status.rs index 5c028531fc..c8a94d7d0c 100644 --- a/nym-api/tests/public-api/unstable_status.rs +++ b/nym-api/tests/public-api/unstable_status.rs @@ -1,6 +1,6 @@ mod utils; +use crate::utils::{base_url, get_gateway_identity_key, get_mixnode_node_id, test_client}; use serde_json::Value; -use utils::{base_url, get_gateway_identity_key, get_mixnode_node_id, test_client}; #[tokio::test] async fn test_get_gateway_unstable_test_results() { @@ -109,7 +109,10 @@ async fn test_get_latest_network_monitor_run_details() { res.status() ); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); let monitor_run_id = json .get("monitor_run_id") .and_then(|v| v.as_number()) diff --git a/nym-api/tests/public-api/utils.rs b/nym-api/tests/public-api/utils.rs index d7b6ad916b..62e51b868f 100644 --- a/nym-api/tests/public-api/utils.rs +++ b/nym-api/tests/public-api/utils.rs @@ -40,7 +40,10 @@ pub async fn get_any_node_id() -> String { .send() .await .unwrap_or_else(|err| panic!("Failed to send request to {}: {}", url, err)); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); json.get("data") .and_then(|list| list.as_array()) @@ -61,7 +64,10 @@ pub async fn get_mixnode_node_id() -> u64 { .send() .await .unwrap_or_else(|err| panic!("Failed to send request to {}: {}", url, err)); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); json.get("data") .and_then(|v| v.as_array()) @@ -88,7 +94,10 @@ pub async fn get_gateway_identity_key() -> String { .send() .await .unwrap_or_else(|err| panic!("Failed to send request to {}: {}", url, err)); - let json: Value = res.json().await.unwrap(); + let json: Value = res + .json() + .await + .unwrap_or_else(|err| panic!("Failed to parse response as JSON: {}", err)); json.get("data") .and_then(|v| v.as_array())