From 606b62d6f5c833106aee4c24eae8d975a7ec9f95 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sat, 27 May 2023 22:46:57 +0200 Subject: [PATCH] Add message tests --- tests/message.rs | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/message.rs diff --git a/tests/message.rs b/tests/message.rs new file mode 100644 index 0000000..6ccda0b --- /dev/null +++ b/tests/message.rs @@ -0,0 +1,80 @@ +mod common; + +use chorus::types; +use std::fs::File; +use std::io::{BufReader, Read}; + +#[tokio::test] +async fn send_message() { + let mut bundle = common::setup().await; + let mut message = types::MessageSendSchema::new( + None, + Some("A Message!".to_string()), + None, + None, + None, + None, + None, + None, + None, + None, + ); + let _ = bundle + .user + .send_message(&mut message, bundle.channel.id.to_string(), None) + .await + .unwrap(); + common::teardown(bundle).await +} + +#[tokio::test] +async fn send_message_attachment() { + let f = File::open("./README.md").unwrap(); + let mut reader = BufReader::new(f); + let mut buffer = Vec::new(); + let mut bundle = common::setup().await; + + reader.read_to_end(&mut buffer).unwrap(); + + let attachment = types::PartialDiscordFileAttachment { + id: None, + filename: "README.md".to_string(), + description: None, + content_type: None, + size: None, + url: None, + proxy_url: None, + width: None, + height: None, + ephemeral: None, + duration_secs: None, + waveform: None, + content: buffer, + }; + + let mut message = types::MessageSendSchema::new( + None, + Some("trans rights now".to_string()), + None, + None, + None, + None, + None, + None, + None, + Some(vec![attachment.clone()]), + ); + + let vec_attach = vec![attachment.clone()]; + let _arg = Some(&vec_attach); + bundle + .user + .send_message( + &mut message, + bundle.channel.id.to_string(), + Some(vec![attachment.clone()]), + ) + .await + .unwrap(); + common::teardown(bundle).await +}