use mcp_gmailcal::errors::GmailApiError;
use mcp_gmailcal::utils::{
decode_base64, encode_base64_url_safe, map_gmail_error, parse_max_results, to_mcp_error,
error_codes::{get_error_description, get_troubleshooting_steps},
error_codes::{AUTH_ERROR, API_ERROR, CONFIG_ERROR, MESSAGE_FORMAT_ERROR, GENERAL_ERROR}
};
use serde_json::json;
#[cfg(test)]
mod utils_extended_tests {
use super::*;
#[test]
fn test_parse_max_results_edge_cases() {
let max_u32_value = json!(u32::MAX);
let result = parse_max_results(Some(max_u32_value), 100);
assert_eq!(result, u32::MAX);
let invalid_string = json!("not_a_number");
let result = parse_max_results(Some(invalid_string), 200);
assert_eq!(result, 200);
}
#[test]
fn test_map_gmail_error_uncovered_branches() {
let api_error = map_gmail_error(GmailApiError::ApiError("standard api error".to_string()));
let debug_str = format!("{:?}", api_error);
assert!(debug_str.contains(&format!("{}", API_ERROR)));
let auth_error_message = "auth test error";
let auth_error = map_gmail_error(GmailApiError::AuthError(auth_error_message.to_string()));
let debug_str = format!("{:?}", auth_error);
assert!(debug_str.contains(&format!("{}", AUTH_ERROR)));
assert!(debug_str.contains(auth_error_message));
}
#[test]
fn test_to_mcp_error_construction() {
let error_msg = "Test error message";
let error = to_mcp_error(error_msg, CONFIG_ERROR);
let debug_str = format!("{:?}", error);
assert!(debug_str.contains(&CONFIG_ERROR.to_string()));
assert!(debug_str.contains(error_msg));
assert!(debug_str.contains("ERROR CODE"));
assert!(debug_str.contains("DETAILS"));
assert!(debug_str.contains("TROUBLESHOOTING"));
assert!(debug_str.contains("SERVER MESSAGE"));
let desc = get_error_description(CONFIG_ERROR);
assert!(debug_str.contains(desc));
let steps = get_troubleshooting_steps(CONFIG_ERROR);
assert!(debug_str.contains(steps));
}
}