Helper function in test::auth to quickly build fake users
New test to verify correct behavior of '/auth/login' route
This commit is contained in:
parent
ab4fe70081
commit
40d4720977
@ -213,7 +213,7 @@ mod auth_tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn feed_n_leave() {
|
fn join_and_leave() {
|
||||||
// Create an invite in our db manually
|
// Create an invite in our db manually
|
||||||
// Use that invite to join
|
// Use that invite to join
|
||||||
// Then leave using our neato /auth/leave route
|
// Then leave using our neato /auth/leave route
|
||||||
@ -279,4 +279,44 @@ mod auth_tests {
|
|||||||
|
|
||||||
assert_eq!(response.status(), Status::Ok);
|
assert_eq!(response.status(), Status::Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bogus_user_insertion(test_name: String, conn: &MysqlConnection) -> User {
|
||||||
|
use crate::models::{USER_OFFLINE, InsertableUser};
|
||||||
|
use schema::users::{self, dsl::*};
|
||||||
|
|
||||||
|
let insertable_user = InsertableUser {
|
||||||
|
name: test_name,
|
||||||
|
secret: encode_param(&utils::new_key()),
|
||||||
|
date: Utc::now().timestamp() as u64,
|
||||||
|
status: USER_OFFLINE
|
||||||
|
};
|
||||||
|
|
||||||
|
let _insertion_result = diesel::insert_into(users::table)
|
||||||
|
.values(&insertable_user)
|
||||||
|
.execute(conn);
|
||||||
|
|
||||||
|
users.filter(date.eq(insertable_user.date)).first::<User>(conn).unwrap()
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn login() {
|
||||||
|
setup_dotenv().unwrap();
|
||||||
|
let app = rocket::ignite()
|
||||||
|
.mount("/auth", routes![login])
|
||||||
|
.attach(DBConn::fairing());
|
||||||
|
let conn = mysql_conn();
|
||||||
|
|
||||||
|
// We need a valid user to login so we'll make one up
|
||||||
|
let bogus_user = bogus_user_insertion("test::auth::login".to_string(), &conn);
|
||||||
|
|
||||||
|
// Finaly we can test our route with the boilerplate ootw
|
||||||
|
let rocket_client = Client::new(app).expect("test::auth::login => client creation failed");
|
||||||
|
let params = format!("id={}&secret={}", bogus_user.id, bogus_user.secret);
|
||||||
|
let response = rocket_client.post("/auth/login")
|
||||||
|
.body(params)
|
||||||
|
.header(ContentType::Form)
|
||||||
|
.dispatch();
|
||||||
|
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user