Finished a test for using an invite via the /invite/join/<code> route
This commit is contained in:
parent
52119d3ea7
commit
68d864710a
@ -14,13 +14,14 @@ use rocket_contrib::json::Json;
|
||||
use diesel::{self, prelude::*};
|
||||
use std::{error, fmt};
|
||||
|
||||
#[allow(dead_code)] // added because these fields are read through rocket, not directly; and rls keeps complainin
|
||||
#[derive(FromForm)]
|
||||
pub struct JoinParams {
|
||||
code: u64,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
#[derive(FromForm, Deserialize)]
|
||||
pub struct AuthKey {
|
||||
id: u64,
|
||||
secret: String,
|
||||
@ -122,6 +123,7 @@ mod auth_tests {
|
||||
use rand::random;
|
||||
use std::env;
|
||||
use dotenv::dotenv;
|
||||
use serde_json::Value;
|
||||
|
||||
fn setup_dotenv() -> Result<(), i32> {
|
||||
match dotenv() {
|
||||
@ -140,6 +142,7 @@ mod auth_tests {
|
||||
let app = rocket::ignite()
|
||||
.mount("/invite", routes![use_invite])
|
||||
.attach(DBConn::fairing());
|
||||
// First we create a new invite
|
||||
let conn = MysqlConnection::establish(&env::var("DATABASE_URL").unwrap()).unwrap();
|
||||
let dt = Utc::now() + Duration::minutes(30);
|
||||
let invite = Invite {
|
||||
@ -155,6 +158,15 @@ mod auth_tests {
|
||||
let rocket_c = Client::new(app).expect("Invalid rocket instance");
|
||||
let mut response = rocket_c.get(format!("/invite/join/{}/{}", invite.id, "billybob")).dispatch();
|
||||
let body: String = response.body_string().unwrap();
|
||||
println!("{}", body)
|
||||
let api_key: Value = serde_json::from_str(&body).unwrap();
|
||||
|
||||
let body_params = format!("id={}&secret={}", api_key["id"], api_key["secret"]);
|
||||
println!("Parameters being sent {}", body_params);
|
||||
let leave_response = rocket_c.get("/auth/leave")
|
||||
.body(body_params)
|
||||
.dispatch();
|
||||
|
||||
assert_eq!(leave_response.status(), Status::Ok);
|
||||
println!("{}", body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user