Added test

This commit is contained in:
kdeng00
2025-07-28 16:31:03 -04:00
parent a949c26933
commit e11524020c
+59
View File
@@ -655,6 +655,11 @@ mod tests {
serde_json::from_slice(&body).unwrap() serde_json::from_slice(&body).unwrap()
} }
pub async fn format_url_with_value(endpoint: &str, value: &uuid::Uuid) -> String {
let last = endpoint.len() - 5;
format!("{}/{value}", &endpoint[0..last])
}
// TODO: Change the name of the function to be more expressive and put into it's own module // TODO: Change the name of the function to be more expressive and put into it's own module
pub mod payload_data { pub mod payload_data {
pub async fn queue_metadata_payload_data(song_queue_id: &uuid::Uuid) -> serde_json::Value { pub async fn queue_metadata_payload_data(song_queue_id: &uuid::Uuid) -> serde_json::Value {
@@ -1998,5 +2003,59 @@ mod tests {
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await; let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
} }
#[tokio::test]
async fn test_download_song() {
let tm_pool = super::db_mgr::get_pool().await.unwrap();
let db_name = super::db_mgr::generate_db_name().await;
match super::db_mgr::create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
let pool = super::db_mgr::connect_to_db(&db_name).await.unwrap();
super::db_mgr::migrations(&pool).await;
let app = super::init::app(pool).await;
let id = test_data::song_id().await.unwrap();
let uri = super::format_url_with_value(crate::callers::endpoints::DOWNLOADSONG, &id).await;
match app
.clone()
.oneshot(
axum::http::Request::builder()
.method(axum::http::Method::GET)
.uri(&uri)
.body(axum::body::Body::empty())
.unwrap(),
)
.await
{
Ok(response) => {
let e = response.into_body();
let mut data = e.into_data_stream();
while let Some(chunk) = data.next().await {
match chunk {
Ok(_data) => {}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
} }
} }