#[cfg(test)] mod tests { use super::*; use dotenv::dotenv; use tonic::Request; use auth_service::auth::auth_service_server::AuthService; use auth_service::auth::{LoginRequest, LoginResponse, ValidateTokenRequest, ValidateTokenResponse}; use auth_service::database::GetUserResponse; use auth_service::database_client::DatabaseClient; use auth_service::grpc::MyAuthService; use auth_service::jwt; // use auth_service::mocks::database_client_mock::MockDatabaseClient; #[tokio::test] async fn test_login() { // dotenv().ok(); // let mut db_client = MockDatabaseClient::new(); // // db_client // .expect_get_user_by_username() // .with(mockall::predicate::eq("test")) // .returning(|user_id| { // Ok(GetUserResponse { // user_id: 1, // username: "test".to_string(), // email: "test@test.com".to_string(), // hashed_password: "test".to_string(), // }) // }); // // // let auth_service = MyAuthService { // db_client, // }; // // // Create a test LoginRequest // let request = Request::new(LoginRequest { // username: "test".into(), // password: "test".into(), // }); // // // Call the login method // let response = auth_service.login(request).await.unwrap().into_inner(); // // // Verify the response // assert!(!response.token.is_empty()); // assert_eq!(response.user_id, "1"); // Replace with the expected user ID } #[tokio::test] async fn test_validate_token() { dotenv().ok(); // let addr = std::env::var("DATABASE_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1:50052".to_string()); // let db_client = DatabaseClient::connect(&addr).await.unwrap(); // // let auth_service = MyAuthService { // db_client, // }; // // // Generate a token for testing // let token = jwt::generate_token("123", Vec::from(["".to_string()])).unwrap(); // // // Create a ValidateTokenRequest // let request = Request::new(ValidateTokenRequest { token }); // // // Call the validate_token method // let response = auth_service.validate_token(request).await.unwrap().into_inner(); // // // Verify the response // assert!(response.valid); // assert_eq!(response.user_id, "123"); } }