tsk-14: Update user profile #15
+90
-1
@@ -131,6 +131,9 @@ mod tests {
|
|||||||
pub mod test_data {
|
pub mod test_data {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
pub const UPDATED_FIRSTNAME: &str = "Bolt";
|
||||||
|
pub const UPDATED_LASTNAME: &str = "Thunder";
|
||||||
|
|
||||||
pub fn get_updated_password(user_id: &uuid::Uuid) -> serde_json::Value {
|
pub fn get_updated_password(user_id: &uuid::Uuid) -> serde_json::Value {
|
||||||
json!({
|
json!({
|
||||||
"username": "somethingsss",
|
"username": "somethingsss",
|
||||||
@@ -234,6 +237,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod responses {
|
||||||
|
pub use soaricarus_auth::callers::login::response as login_responses;
|
||||||
|
pub use soaricarus_auth::callers::register::response as register_responses;
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_hello_world() {
|
async fn test_hello_world() {
|
||||||
let app = init::app().await;
|
let app = init::app().await;
|
||||||
@@ -663,7 +671,8 @@ mod tests {
|
|||||||
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
|
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let parsed_body: callers::login::response::get_user_profile::GetUserProfileResponse =
|
|
||||||
|
let parsed_body: responses::login_responses::get_user_profile::GetUserProfileResponse =
|
||||||
serde_json::from_slice(&body).unwrap();
|
serde_json::from_slice(&body).unwrap();
|
||||||
let user_profile = &parsed_body.data[0];
|
let user_profile = &parsed_body.data[0];
|
||||||
assert!(
|
assert!(
|
||||||
@@ -683,4 +692,84 @@ mod tests {
|
|||||||
|
|
||||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_update_user_profile() {
|
||||||
|
let tm_pool = db_mgr::get_pool().await.unwrap();
|
||||||
|
|
||||||
|
let db_name = db_mgr::generate_db_name().await;
|
||||||
|
|
||||||
|
match db_mgr::create_database(&tm_pool, &db_name).await {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Success");
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
assert!(false, "Error: {:?}", e.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||||
|
|
||||||
|
db::init::migrations(&pool).await;
|
||||||
|
|
||||||
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
|
let usr = get_test_register_request();
|
||||||
|
|
||||||
|
let response = requests::register(&app, &usr).await;
|
||||||
|
|
||||||
|
match response {
|
||||||
|
Ok(resp) => {
|
||||||
|
assert_eq!(
|
||||||
|
resp.status(),
|
||||||
|
StatusCode::CREATED,
|
||||||
|
"Message: {:?} {:?}",
|
||||||
|
resp,
|
||||||
|
usr.username
|
||||||
|
);
|
||||||
|
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let parsed_body: responses::register_responses::Response =
|
||||||
|
serde_json::from_slice(&body).unwrap();
|
||||||
|
let returned_usr = &parsed_body.data[0];
|
||||||
|
|
||||||
|
let user_id = returned_usr.id;
|
||||||
|
assert_eq!(false, user_id.is_nil(), "Id is not populated");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
usr.username, returned_usr.username,
|
||||||
|
"Usernames do not match"
|
||||||
|
);
|
||||||
|
assert!(returned_usr.date_created.is_some(), "Date Created is empty");
|
||||||
|
|
||||||
|
let updated_firstname = test_data::UPDATED_FIRSTNAME;
|
||||||
|
let updated_lastname = test_data::UPDATED_LASTNAME;
|
||||||
|
|
||||||
|
match requests::update_user_profile(&app, &user_id, &updated_firstname, &updated_lastname).await {
|
||||||
|
Ok(resp) => {
|
||||||
|
assert_eq!(StatusCode::OK, resp.status(), "Status is not right");
|
||||||
|
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let parsed_body: responses::login_responses::update_user_profile::UpdateUserProfileResponse =
|
||||||
|
serde_json::from_slice(&body).unwrap();
|
||||||
|
let user_profile = &parsed_body.data[0];
|
||||||
|
|
||||||
|
assert_eq!(updated_firstname, user_profile.firstname, "Firstname has not been updated");
|
||||||
|
assert_eq!(updated_lastname, user_profile.lastname, "Lastname has not been updated");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user