tsk-50: Test refactor
This commit is contained in:
58
src/main.rs
58
src/main.rs
@@ -155,6 +155,23 @@ mod tests {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod requests {
|
||||||
|
use tower::ServiceExt; // for `call`, `oneshot`, and `ready`
|
||||||
|
|
||||||
|
pub async fn register(app: &axum::Router, usr: &icarus_auth::callers::register::request::Request) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
|
// let usr = super::get_test_register_request();
|
||||||
|
let payload = super::get_test_register_payload(&usr);
|
||||||
|
let req = axum::http::Request::builder()
|
||||||
|
.method(axum::http::Method::POST)
|
||||||
|
.uri(crate::callers::endpoints::REGISTER)
|
||||||
|
.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]
|
||||||
async fn test_hello_world() {
|
async fn test_hello_world() {
|
||||||
let app = init::app().await;
|
let app = init::app().await;
|
||||||
@@ -199,18 +216,8 @@ mod tests {
|
|||||||
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();
|
||||||
let payload = get_test_register_payload(&usr);
|
|
||||||
|
|
||||||
let response = app
|
let response = requests::register(&app, &usr).await;
|
||||||
.oneshot(
|
|
||||||
Request::builder()
|
|
||||||
.method(axum::http::Method::POST)
|
|
||||||
.uri(callers::endpoints::REGISTER)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.body(Body::from(payload.to_string()))
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
@@ -244,22 +251,6 @@ mod tests {
|
|||||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod requests {
|
|
||||||
use tower::ServiceExt; // for `call`, `oneshot`, and `ready`
|
|
||||||
|
|
||||||
pub async fn register(app: &axum::Router) -> Result<axum::response::Response, std::convert::Infallible> {
|
|
||||||
let usr = super::get_test_register_request();
|
|
||||||
let payload = super::get_test_register_payload(&usr);
|
|
||||||
let req = axum::http::Request::builder()
|
|
||||||
.method(axum::http::Method::POST)
|
|
||||||
.uri(crate::callers::endpoints::REGISTER)
|
|
||||||
.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]
|
||||||
async fn test_login_user() {
|
async fn test_login_user() {
|
||||||
@@ -283,19 +274,8 @@ mod tests {
|
|||||||
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();
|
||||||
let payload = get_test_register_payload(&usr);
|
|
||||||
|
|
||||||
let response = app
|
let response = requests::register(&app, &usr).await;
|
||||||
.clone()
|
|
||||||
.oneshot(
|
|
||||||
Request::builder()
|
|
||||||
.method(axum::http::Method::POST)
|
|
||||||
.uri(callers::endpoints::REGISTER)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.body(Body::from(payload.to_string()))
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
|
Reference in New Issue
Block a user