Refactor tests
pr CI / Test Suite (pull_request) Failing after 9m52s

This commit is contained in:
2026-08-12 11:54:09 -04:00
parent 8e40744859
commit 3cd5817a14
+188 -169
View File
@@ -193,245 +193,245 @@ mod tests {
pub async fn song_queue_req( pub async fn song_queue_req(
app: &axum::Router, app: &axum::Router,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
// Create multipart form // Create multipart form
let mut form = MultipartForm::default(); match run_post(
let _ = form.add_file("flac", "tests/I/track01.flac"); Some(ReqBody::Multipart((
"flac".to_string(),
// Create request "tests/I/track01.flac".to_string(),
let content_type = form.content_type(); ))),
let body = MultipartBody::from(form); crate::callers::queue::endpoints::QUEUESONG,
let req = axum::http::Request::builder() axum::http::Method::POST,
.method(axum::http::Method::POST) true,
.uri(crate::callers::queue::endpoints::QUEUESONG) )
.header(axum::http::header::CONTENT_TYPE, content_type) .await
.header( {
axum::http::header::AUTHORIZATION, Ok(request) => match app.clone().oneshot(request).await {
super::bearer_auth().await, Ok(response) => Ok(response),
) Err(err) => Err(axum::http::Error::from(err)),
.body(axum::body::Body::from_stream(body)) },
.unwrap(); Err(err) => Err(err),
app.clone().oneshot(req).await }
} }
pub async fn song_queue_link_req( pub async fn song_queue_link_req(
app: &axum::Router, app: &axum::Router,
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
user_id: &uuid::Uuid, user_id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let payload = let payload =
super::payload_data::link_user_to_queued_song(song_queue_id, user_id).await; super::payload_data::link_user_to_queued_song(song_queue_id, user_id).await;
let req = axum::http::Request::builder() match run_post(
.method(axum::http::Method::PATCH) Some(ReqBody::Json(payload)),
.uri(crate::callers::queue::endpoints::QUEUESONGLINKUSERID) crate::callers::queue::endpoints::QUEUESONGLINKUSERID,
.header(axum::http::header::CONTENT_TYPE, "application/json") axum::http::Method::PATCH,
.header( true,
axum::http::header::AUTHORIZATION, )
super::bearer_auth().await, .await
) {
.body(axum::body::Body::from(payload.to_string())) Ok(request) => match app.clone().oneshot(request).await {
.unwrap(); Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
app.clone().oneshot(req).await },
Err(err) => Err(err),
}
} }
pub async fn fetch_queue_req( pub async fn fetch_queue_req(
app: &axum::Router, app: &axum::Router,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let fetch_req = axum::http::Request::builder() match run_post(
.method(axum::http::Method::GET) None,
.uri(crate::callers::queue::endpoints::NEXTQUEUESONG) crate::callers::queue::endpoints::NEXTQUEUESONG,
.header(axum::http::header::CONTENT_TYPE, "application/json") axum::http::Method::GET,
.header( false,
axum::http::header::AUTHORIZATION, )
super::bearer_auth().await, .await
) {
.body(axum::body::Body::empty()) Ok(request) => match app.clone().oneshot(request).await {
.unwrap(); Ok(response) => Ok(response),
app.clone().oneshot(fetch_req).await Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
} }
pub async fn fetch_metadata_queue_req( pub async fn fetch_metadata_queue_req(
app: &axum::Router, app: &axum::Router,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let uri = format!( let uri = format!(
"{}?id={}", "{}?id={}",
crate::callers::queue::endpoints::QUEUEMETADATA, crate::callers::queue::endpoints::QUEUEMETADATA,
id id
); );
let req = axum::http::Request::builder() match run_post(None, &uri, axum::http::Method::GET, false).await {
.method(axum::http::Method::GET) Ok(request) => match app.clone().oneshot(request).await {
.uri(uri) Ok(response) => Ok(response),
.header(axum::http::header::CONTENT_TYPE, "application/json") Err(err) => Err(axum::http::Error::from(err)),
.header( },
axum::http::header::AUTHORIZATION, Err(err) => Err(err),
super::bearer_auth().await, }
)
.body(axum::body::Body::empty())
.unwrap();
app.clone().oneshot(req).await
} }
pub async fn fetch_queue_data_req( pub async fn fetch_queue_data_req(
app: &axum::Router, app: &axum::Router,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let raw_uri = String::from(crate::callers::queue::endpoints::QUEUESONGDATA); let raw_uri = String::from(crate::callers::queue::endpoints::QUEUESONGDATA);
let end_index = raw_uri.len() - 4; let end_index = raw_uri.len() - 4;
let mut uri: String = (&raw_uri[..end_index]).to_string(); let mut uri: String = (&raw_uri[..end_index]).to_string();
uri += &id.to_string(); uri += &id.to_string();
let req = axum::http::Request::builder()
.method(axum::http::Method::GET)
.uri(uri)
.header(
axum::http::header::CONTENT_TYPE,
simeta::detection::song::constants::mime::FLAC,
)
.header(
axum::http::header::AUTHORIZATION,
super::bearer_auth().await,
)
.body(axum::body::Body::empty())
.unwrap();
app.clone().oneshot(req).await match run_post(None, &uri, axum::http::Method::GET, false).await {
Ok(request) => match app.clone().oneshot(request).await {
Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
} }
pub async fn upload_coverart_queue_req( pub async fn upload_coverart_queue_req(
app: &axum::Router, app: &axum::Router,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let mut form = MultipartForm::default(); match run_post(
let _ = form.add_file( Some(ReqBody::Multipart((
simeta::detection::coverart::constants::JPEG_TYPE, simeta::detection::coverart::constants::JPEG_TYPE.to_string(),
"tests/I/Coverart-1.jpg", "tests/I/Coverart-1.jpg".to_string(),
); ))),
crate::callers::queue::endpoints::QUEUECOVERART,
// Create request axum::http::Method::POST,
let content_type = form.content_type(); true,
let body = MultipartBody::from(form); )
.await
let req = axum::http::Request::builder() {
.method(axum::http::Method::POST) Ok(request) => match app.clone().oneshot(request).await {
.uri(crate::callers::queue::endpoints::QUEUECOVERART) Ok(response) => Ok(response),
.header(axum::http::header::CONTENT_TYPE, content_type) Err(err) => Err(axum::http::Error::from(err)),
.header( },
axum::http::header::AUTHORIZATION, Err(err) => Err(err),
super::bearer_auth().await, }
)
.body(axum::body::Body::from_stream(body))
.unwrap();
app.clone().oneshot(req).await
} }
pub async fn queue_metadata_req( pub async fn queue_metadata_req(
app: &axum::Router, app: &axum::Router,
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let payload = super::payload_data::queue_metadata(&song_queue_id).await; let payload = super::payload_data::queue_metadata(&song_queue_id).await;
let req = axum::http::Request::builder() match run_post(
.method(axum::http::Method::POST) Some(ReqBody::Json(payload)),
.uri(crate::callers::queue::endpoints::QUEUEMETADATA) crate::callers::queue::endpoints::QUEUEMETADATA,
.header(axum::http::header::CONTENT_TYPE, "application/json") axum::http::Method::POST,
.header( true,
axum::http::header::AUTHORIZATION, )
super::bearer_auth().await, .await
) {
.body(axum::body::Body::from(payload.to_string())) Ok(request) => match app.clone().oneshot(request).await {
.unwrap(); Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
app.clone().oneshot(req).await },
Err(err) => Err(err),
}
} }
pub async fn coverart_queue_song_queue_link_req( pub async fn coverart_queue_song_queue_link_req(
app: &axum::Router, app: &axum::Router,
coverart_id: &uuid::Uuid, coverart_id: &uuid::Uuid,
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let payload = super::payload_data::link_queued_coverart_to_queued_song( let payload = super::payload_data::link_queued_coverart_to_queued_song(
song_queue_id, song_queue_id,
coverart_id, coverart_id,
) )
.await; .await;
let req = axum::http::Request::builder()
.method(axum::http::Method::PATCH)
.uri(crate::callers::queue::endpoints::QUEUECOVERARTLINK)
.header(axum::http::header::CONTENT_TYPE, "application/json")
.header(
axum::http::header::AUTHORIZATION,
super::bearer_auth().await,
)
.body(axum::body::Body::from(payload.to_string()))
.unwrap();
app.clone().oneshot(req).await match run_post(
Some(ReqBody::Json(payload)),
crate::callers::queue::endpoints::QUEUECOVERARTLINK,
axum::http::Method::PATCH,
true,
)
.await
{
Ok(request) => match app.clone().oneshot(request).await {
Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
} }
pub async fn create_coverart_req( pub async fn create_coverart_req(
app: &axum::Router, app: &axum::Router,
song_id: &uuid::Uuid, song_id: &uuid::Uuid,
coverart_id: &uuid::Uuid, coverart_id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let payload = super::payload_data::create_coverart(song_id, coverart_id).await; let payload = super::payload_data::create_coverart(song_id, coverart_id).await;
let req = axum::http::Request::builder() match run_post(
.method(axum::http::Method::POST) Some(ReqBody::Json(payload)),
.uri(crate::callers::endpoints::CREATECOVERART) crate::callers::endpoints::CREATECOVERART,
.header(axum::http::header::CONTENT_TYPE, "application/json") axum::http::Method::POST,
.header( true,
axum::http::header::AUTHORIZATION, )
super::bearer_auth().await, .await
) {
.body(axum::body::Body::from(payload.to_string())) Ok(request) => match app.clone().oneshot(request).await {
.unwrap(); Ok(response) => Ok(response),
app.clone().oneshot(req).await Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
} }
pub async fn create_song_req( pub async fn create_song_req(
app: &axum::Router, app: &axum::Router,
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
user_id: &uuid::Uuid, user_id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let payload = super::payload_data::create_song(song_queue_id, user_id).await; let payload = super::payload_data::create_song(song_queue_id, user_id).await;
let req = axum::http::Request::builder() match run_post(
.method(axum::http::Method::POST) Some(ReqBody::Json(payload)),
.uri(crate::callers::endpoints::CREATESONG) crate::callers::endpoints::CREATESONG,
.header(axum::http::header::CONTENT_TYPE, "application/json") axum::http::Method::POST,
.header( true,
axum::http::header::AUTHORIZATION, )
super::bearer_auth().await, .await
) {
.body(axum::body::Body::from(payload.to_string())) Ok(request) => match app.clone().oneshot(request).await {
.unwrap(); Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
app.clone().oneshot(req).await },
Err(err) => Err(err),
}
} }
pub async fn update_song_queue_status_req( pub async fn update_song_queue_status_req(
app: &axum::Router, app: &axum::Router,
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, axum::http::Error> {
let payload = let payload =
super::payload_data::update_song_queue_status_to_ready(song_queue_id).await; super::payload_data::update_song_queue_status_to_ready(song_queue_id).await;
let req = axum::http::Request::builder() match run_post(
.method(axum::http::Method::PATCH) Some(ReqBody::Json(payload)),
.uri(crate::callers::queue::endpoints::QUEUESONG) crate::callers::queue::endpoints::QUEUESONG,
.header(axum::http::header::CONTENT_TYPE, "application/json") axum::http::Method::PATCH,
.header( true,
axum::http::header::AUTHORIZATION, )
super::bearer_auth().await, .await
) {
.body(axum::body::Body::from(payload.to_string())) Ok(request) => match app.clone().oneshot(request).await {
.unwrap(); Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
app.clone().oneshot(req).await },
Err(err) => Err(err),
}
} }
pub async fn get_queued_coverart( pub async fn get_queued_coverart(
@@ -446,13 +446,9 @@ mod tests {
match run_post(None, &uri, axum::http::Method::GET, false).await { match run_post(None, &uri, axum::http::Method::GET, false).await {
Ok(request) => match app.clone().oneshot(request).await { Ok(request) => match app.clone().oneshot(request).await {
Ok(response) => { Ok(response) => Ok(response),
Ok(response) Err(err) => Err(axum::http::Error::from(err)),
} },
Err(err) => {
Err(axum::http::Error::from(err))
}
}
Err(err) => { Err(err) => {
Err(err) Err(err)
// Err(std::convert::Infallible::from(err)) // Err(std::convert::Infallible::from(err))
@@ -478,7 +474,7 @@ mod tests {
pub enum ReqBody { pub enum ReqBody {
Json(serde_json::Value), Json(serde_json::Value),
Multipart((String, String)),
} }
pub async fn run_post( pub async fn run_post(
@@ -496,8 +492,16 @@ mod tests {
); );
// axum::body::Body::from(payload.unwrap().to_string()) // axum::body::Body::from(payload.unwrap().to_string())
match payload.unwrap() { match payload.unwrap() {
ReqBody::Json(val) => { ReqBody::Json(val) => axum::body::Body::from(val.to_string()),
axum::body::Body::from(val.to_string()) ReqBody::Multipart((t, p)) => {
let mut form = MultipartForm::default();
let _ = form.add_file(t, p);
// Create request
let content_type = form.content_type();
println!("Content: {content_type:?}");
let body = MultipartBody::from(form);
axum::body::Body::from_stream(body)
} }
} }
} else { } else {
@@ -526,7 +530,7 @@ mod tests {
// Flow for queueing song // Flow for queueing song
pub async fn queue_song_flow( pub async fn queue_song_flow(
app: &axum::Router, app: &axum::Router,
) -> Result<(axum::response::Response, uuid::Uuid), std::convert::Infallible> { ) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> {
match super::request::song_queue_req(&app).await { match super::request::song_queue_req(&app).await {
Ok(response) => { Ok(response) => {
let resp = super::util::get_resp_data::< let resp = super::util::get_resp_data::<
@@ -569,6 +573,10 @@ mod tests {
Err(err) => Err(err), Err(err) => Err(err),
} }
} }
Err(err) => {
assert!(false, "Error: {:?}", err);
Err(err)
}
} }
} }
Err(err) => Err(err), Err(err) => Err(err),
@@ -618,15 +626,23 @@ mod tests {
Err(err) => Err(err), Err(err) => Err(err),
} }
} }
Err(err) => {
assert!(false, "Error: {:?}", err);
Err(err)
}
} }
} }
Err(err) => {
assert!(false, "Error: {:?}", err);
Err(err)
}
} }
} }
// Returns coverart response and song_queue_id // Returns coverart response and song_queue_id
pub async fn queue_song_and_coverart_flow( pub async fn queue_song_and_coverart_flow(
app: &axum::Router, app: &axum::Router,
) -> Result<(axum::response::Response, uuid::Uuid), std::convert::Infallible> { ) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> {
match queue_song_flow(&app).await { match queue_song_flow(&app).await {
Ok((song_response, user_id)) => { Ok((song_response, user_id)) => {
let resp = super::util::get_resp_data::< let resp = super::util::get_resp_data::<
@@ -1711,6 +1727,9 @@ mod tests {
} }
} }
} }
Err(err) => {
assert!(false, "Error: {:?}", err);
}
} }
} }
Err(err) => { Err(err) => {