#![allow(dead_code)]
use std::sync::Once;
use pickcat_api_collection::PickcatAccound;
use pickcat_api_collection::auth::UserBehavior;
pub fn init_logging() {
static INIT: Once = Once::new();
INIT.call_once(|| {
dotenvy::dotenv().ok();
let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.try_init();
log::info!("test logging initialized");
});
}
static ACCOUNT: tokio::sync::OnceCell<PickcatAccound> = tokio::sync::OnceCell::const_new();
pub static LIVE_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
pub async fn account() -> &'static PickcatAccound {
ACCOUNT
.get_or_init(|| async {
init_logging();
let username = std::env::var("USERNAME").expect("USERNAME is not set (add it to .env)");
let password = std::env::var("PASSWORD").expect("PASSWORD is not set (add it to .env)");
log::info!("logging in as {username}");
let account = PickcatAccound::new(&username, &password)
.await
.expect("failed to construct PickcatAccound");
let session = account
.get_current_user_session()
.await
.expect("login failed; check USERNAME/PASSWORD in .env");
log::info!(
"login ok: user id={}, username={}, level=Lv.{}, expiresAt={}",
session.user.id,
session.user.username,
session.user.level.current,
session.expires_at
);
account
})
.await
}
pub async fn mock_account(server: &wiremock::MockServer) -> PickcatAccound {
PickcatAccound::with_base_url("mock-user", "mock-password", &server.uri())
.await
.expect("construct account against mock server")
}