use mcp_gmailcal::gmail_api::{GmailService};
use mcp_gmailcal::config::Config;
use mockito;
use serde_json::json;
use std::env;
fn create_test_config() -> 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: Some("test_access_token".to_string()),
token_refresh_threshold: 300,
token_expiry_buffer: 60,
}
}
#[ignore]
#[tokio::test(flavor = "multi_thread")]
async fn test_check_connection() {
let mut server = mockito::Server::new();
let response = json!({
"emailAddress": "test@example.com",
"messagesTotal": 100,
"threadsTotal": 50,
"historyId": "12345"
});
let mock = server.mock("GET", "/gmail/v1/users/me/profile")
.with_status(200)
.with_header("content-type", "application/json")
.with_body(response.to_string())
.create();
env::set_var("GMAIL_API_BASE_URL", server.url());
let mut gmail_service = GmailService::new(&create_test_config()).unwrap();
let result = gmail_service.check_connection().await;
mock.assert();
assert!(result.is_ok());
let (email, count) = result.unwrap();
assert_eq!(email, "test@example.com");
assert_eq!(count, 100);
}