added 2 funcitonal tests
This commit is contained in:
parent
7fa0eeddf1
commit
f0159c40c4
42
src/main.rs
42
src/main.rs
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue