Test changes
soaricarus_auth Build / Check (pull_request) Successful in 46s
soaricarus_auth Build / Rustfmt (pull_request) Successful in 59s
soaricarus_auth Build / Test Suite (pull_request) Failing after 1m2s
soaricarus_auth Build / Clippy (pull_request) Successful in 1m3s
soaricarus_auth Build / build (pull_request) Successful in 3m13s
soaricarus_auth Build / Check (pull_request) Successful in 46s
soaricarus_auth Build / Rustfmt (pull_request) Successful in 59s
soaricarus_auth Build / Test Suite (pull_request) Failing after 1m2s
soaricarus_auth Build / Clippy (pull_request) Successful in 1m3s
soaricarus_auth Build / build (pull_request) Successful in 3m13s
This commit is contained in:
+97
-21
@@ -258,6 +258,20 @@ mod tests {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod test_data {
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
pub fn get_updated_password(user_id: &uuid::Uuid) -> serde_json::Value {
|
||||||
|
json!({
|
||||||
|
"username": "somethingsss",
|
||||||
|
"user_id": user_id,
|
||||||
|
"current_password": "Raindown!",
|
||||||
|
"updated_password": "SpeakWithUrChest22!",
|
||||||
|
"confirmed_password": "SpeakWithUrChest22!"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod requests {
|
pub mod requests {
|
||||||
use tower::ServiceExt; // for `call`, `oneshot`, and `ready`
|
use tower::ServiceExt; // for `call`, `oneshot`, and `ready`
|
||||||
|
|
||||||
@@ -290,6 +304,21 @@ mod tests {
|
|||||||
|
|
||||||
app.clone().oneshot(req).await
|
app.clone().oneshot(req).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn update_password(
|
||||||
|
app: &axum::Router,
|
||||||
|
user_id: &uuid::Uuid,
|
||||||
|
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
|
let payload = super::test_data::get_updated_password(user_id);
|
||||||
|
let req = axum::http::Request::builder()
|
||||||
|
.method(axum::http::Method::PATCH)
|
||||||
|
.uri(crate::callers::endpoints::LOGIN)
|
||||||
|
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||||
|
.body(axum::body::Body::from(payload.to_string()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
app.clone().oneshot(req).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -420,29 +449,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert!(returned_usr.date_created.is_some(), "Date Created is empty");
|
assert!(returned_usr.date_created.is_some(), "Date Created is empty");
|
||||||
|
|
||||||
/*
|
|
||||||
let login_payload = json!({
|
|
||||||
"username": &usr.username,
|
|
||||||
"password": &usr.password,
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
let mut n_usr = callers::login::request::Request::default();
|
let mut n_usr = callers::login::request::Request::default();
|
||||||
n_usr.username = usr.username.clone();
|
n_usr.username = usr.username.clone();
|
||||||
n_usr.password = usr.password.clone();
|
n_usr.password = usr.password.clone();
|
||||||
|
|
||||||
/*
|
|
||||||
match app
|
|
||||||
.oneshot(
|
|
||||||
Request::builder()
|
|
||||||
.method(axum::http::Method::POST)
|
|
||||||
.uri(callers::endpoints::LOGIN)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.body(Body::from(login_payload.to_string()))
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
*/
|
|
||||||
match requests::login(&app, &n_usr).await {
|
match requests::login(&app, &n_usr).await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
assert_eq!(StatusCode::OK, resp.status(), "Status is not right");
|
assert_eq!(StatusCode::OK, resp.status(), "Status is not right");
|
||||||
@@ -607,9 +617,75 @@ mod tests {
|
|||||||
|
|
||||||
db::init::migrations(&pool).await;
|
db::init::migrations(&pool).await;
|
||||||
|
|
||||||
let _app = init::routes().await.layer(axum::Extension(pool));
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
let _usr = get_test_register_request();
|
let usr = get_test_register_request();
|
||||||
|
|
||||||
|
match requests::register(&app, &usr).await {
|
||||||
|
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: callers::register::response::Response =
|
||||||
|
serde_json::from_slice(&body).unwrap();
|
||||||
|
let returned_usr = &parsed_body.data[0];
|
||||||
|
|
||||||
|
assert_eq!(false, returned_usr.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 mut n_usr = callers::login::request::Request::default();
|
||||||
|
n_usr.username = usr.username.clone();
|
||||||
|
n_usr.password = usr.password.clone();
|
||||||
|
|
||||||
|
match requests::login(&app, &n_usr).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: callers::login::response::Response =
|
||||||
|
serde_json::from_slice(&body).unwrap();
|
||||||
|
let login_result = &parsed_body.data[0];
|
||||||
|
assert!(!login_result.id.is_nil(), "Id is nil");
|
||||||
|
|
||||||
|
match requests::update_password(&app, &login_result.id).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: callers::login::response::update_password::Response =
|
||||||
|
serde_json::from_slice(&body).unwrap();
|
||||||
|
let id = parsed_body.data[0];
|
||||||
|
|
||||||
|
assert_eq!(id, login_result.id, "Ids do not match");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user