first integrated unit test to start replacing bash test suite

This commit is contained in:
shockrah 2020-08-12 19:48:09 -07:00
parent da01c13ac5
commit 14f91e2240
2 changed files with 37 additions and 1 deletions

View File

@ -134,10 +134,45 @@ pub async fn create(pool: &Pool, response: &mut Response<Body>, 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());
}
}

View File

@ -23,6 +23,7 @@ use mysql_async::Pool;
use dotenv::dotenv;
use clap::{Arg, App};
mod testing;
mod auth;
use auth::AuthReason;