use mcp_gmailcal::config::{Config, get_token_expiry_seconds};
use mcp_gmailcal::errors::ConfigError;
use std::env;
#[test]
fn test_api_url_constants() {
assert_eq!(mcp_gmailcal::config::GMAIL_API_BASE_URL, "https://gmail.googleapis.com/gmail/v1");
assert_eq!(mcp_gmailcal::config::OAUTH_TOKEN_URL, "https://oauth2.googleapis.com/token");
}
#[test]
fn test_token_expiry_seconds() {
let original = env::var("TOKEN_EXPIRY_SECONDS").ok();
env::remove_var("TOKEN_EXPIRY_SECONDS");
assert_eq!(get_token_expiry_seconds(), 3540);
env::set_var("TOKEN_EXPIRY_SECONDS", "300"); assert_eq!(get_token_expiry_seconds(), 300);
env::set_var("TOKEN_EXPIRY_SECONDS", "not_a_number");
assert_eq!(get_token_expiry_seconds(), 3540);
match original {
Some(val) => env::set_var("TOKEN_EXPIRY_SECONDS", val),
None => env::remove_var("TOKEN_EXPIRY_SECONDS"),
}
}
#[test]
fn test_config_direct_creation() {
let config = Config {
client_id: "test_client_id".to_string(),
client_secret: "test_client_secret".to_string(),
refresh_token: "test_refresh_token".to_string(),
access_token: None,
token_refresh_threshold: 300, token_expiry_buffer: 60, };
assert_eq!(config.client_id, "test_client_id");
assert_eq!(config.client_secret, "test_client_secret");
assert_eq!(config.refresh_token, "test_refresh_token");
assert_eq!(config.access_token, None);
let config_with_token = Config {
client_id: "test_client_id".to_string(),
client_secret: "test_client_secret".to_string(),
refresh_token: "test_refresh_token".to_string(),
access_token: Some("test_access_token".to_string()),
token_refresh_threshold: 300, token_expiry_buffer: 60, };
assert_eq!(config_with_token.client_id, "test_client_id");
assert_eq!(config_with_token.client_secret, "test_client_secret");
assert_eq!(config_with_token.refresh_token, "test_refresh_token");
assert_eq!(config_with_token.access_token, Some("test_access_token".to_string()));
}
#[test]
fn test_env_error_conversion() {
let var_error = env::VarError::NotPresent;
let config_error = ConfigError::from(var_error);
match config_error {
ConfigError::EnvError(_) => {
},
_ => panic!("Expected EnvError variant"),
}
}