diff --git a/server/src/invites.rs b/server/src/invites.rs index 0e4eae1..45077d1 100644 --- a/server/src/invites.rs +++ b/server/src/invites.rs @@ -134,10 +134,45 @@ pub async fn create(pool: &Pool, response: &mut Response, params: Value) { }; match insert_new_invite(&pool, &invite).await { - Ok(_) => *response.body_mut() = Body::from("yes"), + Ok(_) => {}, Err(mysqle) => { println!("\tINVITES::CREATE::ERROR: {}", mysqle); *response.status_mut() = StatusCode::BAD_REQUEST; } } } + + +#[cfg(test)] +mod invites_test { + /* + * INVITE CREATION + * Good - Bad - Malicious + */ + + use crate::testing::{get_pool, hyper_resp}; + use hyper::StatusCode; + use serde_json::Value; + + #[tokio::test] + async fn create_invite_good() { + // Generation of data + let p = get_pool(); + let mut resp = hyper_resp(); + // expected params + let params: Value = serde_json::from_str(r#" + { + "uses": 3, + "expire": null + } + "#).unwrap(); + + // Collection + super::join(&p, &mut resp, params).await; + let _ = p.disconnect().await; + + // Analysis - todo + assert_eq!(StatusCode::OK, resp.status()); + println!("Body contents (should be nothing) => {:?}", resp.body()); + } +} diff --git a/server/src/main.rs b/server/src/main.rs index 3cb548a..a074fc0 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -23,6 +23,7 @@ use mysql_async::Pool; use dotenv::dotenv; use clap::{Arg, App}; +mod testing; mod auth; use auth::AuthReason;