From 962f57cd04c63845f10ac4b4190a60dca0b31a9f Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 25 Jul 2025 18:08:24 -0400 Subject: [PATCH] Got the test to work --- src/main.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a77b90a..dbb2aff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1815,6 +1815,8 @@ mod tests { } pub mod after_song_queue { + use tower::ServiceExt; + #[tokio::test] async fn test_get_songs() { let tm_pool = super::db_mgr::get_pool().await.unwrap(); @@ -1833,7 +1835,50 @@ mod tests { // super::super::db::migrations(&pool).await; super::db_mgr::migrations(&pool).await; - let _app = super::init::app(pool).await; + /* + let uri = format!("{}?id={}", crate::callers::endpoints::QUEUEMETADATA, id); + + let req = axum::http::Request::builder() + .method(axum::http::Method::GET) + .uri(uri) + .header(axum::http::header::CONTENT_TYPE, "application/json") + .body(axum::body::Body::empty()) + .unwrap(); + + app.clone().oneshot(req).await + */ + let id_result = uuid::Uuid::parse_str("44cf7940-34ff-489f-9124-d0ec90a55af9"); + let mut id = uuid::Uuid::nil(); + match id_result { + Ok(val) => { + id = val; + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + }; + let uri = format!("{}?id={id}", crate::callers::endpoints::GETSONGS); + + let app = super::init::app(pool).await; + match app.clone().oneshot( + axum::http::Request::builder() + .method(axum::http::Method::GET) + .uri(uri) + .header(axum::http::header::CONTENT_TYPE, "application/json") + .body(axum::body::Body::empty()) + .unwrap() + ).await { + Ok(response) => { + let resp = super::get_resp_data::(response).await; + assert_eq!(false, resp.data.is_empty(), "Should not be empty"); + + let song = resp.data[0].clone(); + assert_eq!(id, song.id, "Id does not match {song:?}"); + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await; }