From f0159c40c4f376185650bb7fe931aaee47cfe65f Mon Sep 17 00:00:00 2001 From: Alie Date: Sun, 21 Jan 2024 17:23:43 +0100 Subject: [PATCH] added 2 funcitonal tests --- src/main.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/main.rs b/src/main.rs index 85dc04c..602b368 100644 --- a/src/main.rs +++ b/src/main.rs @@ -263,3 +263,45 @@ async fn register(config: &Config) -> DynResult { Ok(mastodon) } + +#[cfg(test)] +mod tests { + + use reqwest::StatusCode; + + use super::*; + const TMPTESTDIR: &str = "/tmp/botimage"; + + #[tokio::test] + async fn fetch_url_should_fetch() { + fetch_url( + &"https://2.gravatar.com/avatar/be8eb8426d68e4beb50790647eda6f6b".to_string(), + &TMPTESTDIR.to_string(), + ) + .await + .unwrap(); + std::fs::read(TMPTESTDIR).unwrap(); + } + + #[tokio::test] + async fn post_should_post() { + let client = reqwest::Client::new(); + let config = get_config(); + let account = get_account(&config).await; + let msg = format!("Test!"); + + let status = post(&account, &msg, Visibility::Direct).await.unwrap(); + let response = client + .get(dbg!(format!( + "{}/api/v1/statuses/{}", + &config.bot.instance, + &status.id.to_string() + ))) + .bearer_auth(dbg!(&account.data.token)) + .send() + .await + .unwrap(); + + assert_eq!(response.status(), StatusCode::OK) + } +}