send_message_good works as intented and passes!

This commit is contained in:
shockrah 2020-08-20 19:20:04 -07:00
parent aa01d0ee90
commit e46ea5080d

View File

@ -102,4 +102,47 @@ mod messaging_tests {
assert_ne!(StatusCode::OK, resp.status());
}
#[tokio::test]
async fn send_message_good() {
use crate::members::insert_new_member;
use crate::perms::GENERAL_NEW;
use mysql_async::params;
use mysql_async::prelude::Queryable;
use crate::testing::tmp_channel_params;
let p = get_pool();
let mut resp = hyper_resp();
let tmp_chan = tmp_channel_params(&p, "sample").await;
const TMP_NAME: &'static str = "bs user";
let temp_member = insert_new_member(&p, TMP_NAME.into(), GENERAL_NEW).await.unwrap();
let params: Value = serde_json::from_str(&format!(r#"
{{
"id": {},
"channel": "{}",
"content": "bs message"
}}
"#, temp_member.id, tmp_chan.name)).unwrap();
super::send_message(&p, &mut resp, params).await;
if resp.status() == StatusCode::BAD_REQUEST {
panic!("{:?}", resp.body());
}
// Destroy the the message and the user that we created
let conn = match p.get_conn().await {
Ok(c) => c,
Err(e) => panic!("Could not get connection to db during send_message_good:\nIssue:\t{}", e)
};
let conn = conn.drop_exec("DELETE FROM messages WHERE author_id = :id", params!{"id" => temp_member.id}).await.unwrap();
let conn = conn.drop_exec("DELETE FROM members WHERE id = :id", params!{"id" => temp_member.id}).await.unwrap();
let _ = conn.drop_exec("DELETE FROM channels WHERE name = :name", params!{"name" => tmp_chan.name}).await;
}
}