From 6fa154ecf4ae538a85a769e8791ea74ae4ce0010 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Jul 2025 19:47:01 -0400 Subject: [PATCH] Added test #156 --- src/main.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/main.rs b/src/main.rs index 8b507e3..80c4c51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -261,6 +261,22 @@ mod tests { app.clone().oneshot(req).await } + async fn song_queue_link_req(app: &axum::Router, song_queue_id: &uuid::Uuid, user_id: &uuid::Uuid) -> Result { + let payload = serde_json::json!({ + "song_queue_id": song_queue_id, + "user_id": user_id + }); + + let req = axum::http::Request::builder() + .method(axum::http::Method::PATCH) + .uri(crate::callers::endpoints::QUEUESONGLINKUSERID) + .header(axum::http::header::CONTENT_TYPE, "application/json") + .body(axum::body::Body::from(payload.to_string())) + .unwrap(); + + app.clone().oneshot(req).await + } + async fn fetch_queue_req( app: &axum::Router, ) -> Result { @@ -663,6 +679,57 @@ mod tests { let _ = db_mgr::drop_database(&tm_pool, &db_name).await; } + #[tokio::test] + async fn test_song_queue_link_user_id() { + 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(err) => { + assert!(false, "Error: {:?}", err); + } + } + + let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); + db::migrations(&pool).await; + + let app = init::app(pool).await; + + match song_queue_req(&app).await { + Ok(response) => { + let resp = + get_resp_data::(response).await; + assert_eq!(false, resp.data.is_empty(), "Should not be empty"); + assert_eq!(false, resp.data[0].is_nil(), "Should not be empty"); + + let song_queue_id = &resp.data[0]; + let user_id = uuid::Uuid::new_v4(); + println!("User Id: {user_id:?}"); + + match song_queue_link_req(&app, &song_queue_id, &user_id).await { + Ok(response) => { + let resp = get_resp_data::(response).await; + let collected_user_id = &resp.data[0]; + + assert!(!collected_user_id.is_nil(), "Collected user id should not be nil {collected_user_id:?}"); + assert_eq!(user_id, *collected_user_id, "User Id is different. First {user_id:?} Second {collected_user_id:?}"); + } + Err(err) => { + assert!(false, "Error: {err:?} songQueue Id {song_queue_id:?} user id {user_id:?}"); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }; + + let _ = db_mgr::drop_database(&tm_pool, &db_name).await; + } + #[tokio::test] async fn test_song_fetch_queue_item() { let tm_pool = db_mgr::get_pool().await.unwrap();