Skip to content

Commit

Permalink
Add: More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephira58 committed Mar 26, 2023
1 parent f4c7797 commit 033224a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use self_update::cargo_crate_version;


#[test]
fn test_get_insult() {
println!("\nFetching insult from https://insult.mattbas.org/api/insult...");
Expand All @@ -25,4 +29,34 @@ mod tests {
println!("Affirmation fetched!");
assert_eq!(x, x);
}
}

#[test]
fn test_send_message() {
println!("\nSending message...");
let mut request_body = HashMap::new();
request_body.insert("content", "unit test");
request_body.insert("username", "xanthus");
request_body.insert("avatar_url", "https://cdn.discordapp.com/avatars/292971545956188160/2a77b119a3f8ccedfbd513825eec97a5.png?size=1024");

reqwest::Client::new()
.post("https://discord.com/api/webhooks/1071132108392775720/uYFy-Iyxfi8pO98_PNF3f8fgATHNKzYkSDJ1c4S9_5lvB-axPyTQlF5iHl29cW-6JyPO")
.json(&request_body)
.send();
println!("Message sent!");
}

#[test]
pub fn download_update() -> Result<(), Box<dyn (::std::error::Error)>> {
let status = self_update::backends::github::Update::configure()
.repo_owner("Xanthus58")
.repo_name("webhook_sender")
.bin_name("github")
.show_download_progress(true)
.no_confirm(true)
.current_version(cargo_crate_version!())
.build()?
.update()?;
println!("Update status: `{}`!", status.version());
Ok(())
}
}

0 comments on commit 033224a

Please sign in to comment.