use ig_client::prelude::*;
use tokio::runtime::Runtime;
use tracing::info;
pub fn create_test_client() -> Client {
Client::try_new().expect("client construction should succeed")
}
pub fn login_with_account_switch() -> Session {
setup_logger();
let rt = Runtime::new().expect("Failed to create runtime");
rt.block_on(async {
login_with_account_switch_async()
.await
.expect("Failed to login")
})
}
pub async fn login_with_account_switch_async() -> Result<Session, String> {
setup_logger();
let http_client = HttpClient::new_lazy(Config::default())
.map_err(|e| format!("lazy HTTP client construction failed: {e}"))?;
match http_client.get_session().await {
Ok(session) => {
info!("Logged in with account: {}", session.account_id);
Ok(session)
}
Err(e) => Err(format!("Failed to login: {e:?}")),
}
}