Added test

This commit is contained in:
kdeng00
2025-07-27 13:58:30 -04:00
parent c1672968ca
commit 5d4d9abf46
+70 -19
View File
@@ -1820,6 +1820,7 @@ mod tests {
}
pub mod after_song_queue {
use futures::StreamExt;
use tower::ServiceExt;
#[tokio::test]
@@ -1841,15 +1842,7 @@ mod tests {
let app = super::init::app(pool).await;
let mut id = uuid::Uuid::nil();
match uuid::Uuid::parse_str("44cf7940-34ff-489f-9124-d0ec90a55af9") {
Ok(val) => {
id = val;
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
};
let id = test_data::coverart_id().await.unwrap();
let uri = format!("{}?id={id}", crate::callers::endpoints::GETSONGS);
@@ -1902,16 +1895,7 @@ mod tests {
let app = super::init::app(pool).await;
let mut id = uuid::Uuid::nil();
match uuid::Uuid::parse_str("996122cd-5ae9-4013-9934-60768d3006ed") {
Ok(val) => {
id = val;
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
};
let id = test_data::coverart_id().await.unwrap();
let uri = format!("{}?id={id}", crate::callers::endpoints::GETCOVERART);
@@ -1944,5 +1928,72 @@ mod tests {
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
pub mod test_data {
pub async fn song_id() -> Result<uuid::Uuid, uuid::Error> {
uuid::Uuid::parse_str("44cf7940-34ff-489f-9124-d0ec90a55af9")
}
pub async fn coverart_id() -> Result<uuid::Uuid, uuid::Error> {
uuid::Uuid::parse_str("996122cd-5ae9-4013-9934-60768d3006ed")
}
}
#[tokio::test]
async fn test_stream_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 my_url = crate::callers::endpoints::STREAMSONG;
let last = my_url.len() - 5;
let uri = format!("{}/{id}", &my_url[0..last]);
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;
}
}
}