added 2 funcitonal tests

This commit is contained in:
Alie 2024-01-21 17:23:43 +01:00
parent 7fa0eeddf1
commit f0159c40c4
1 changed files with 42 additions and 0 deletions

View File

@ -263,3 +263,45 @@ async fn register(config: &Config) -> DynResult<Mastodon> {
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)
}
}