From 0f1c3bb70fb2dfba8b6627241b0636824a48ce52 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 12 Aug 2026 11:07:09 -0400 Subject: [PATCH] Test refactor --- src/main.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index af7f0a4..5acb0db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -437,13 +437,30 @@ mod tests { pub async fn get_queued_coverart( app: &axum::Router, coverart_queue_id: &uuid::Uuid, - ) -> Result { + ) -> Result { let uri = format!( "{}?id={}", crate::callers::queue::endpoints::QUEUECOVERART, coverart_queue_id ); + 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) + // Err(std::convert::Infallible::from(err)) + // Err(err) + } + } + + /* let req = axum::http::Request::builder() .method(axum::http::Method::GET) .uri(uri) @@ -456,6 +473,52 @@ mod tests { .unwrap(); app.clone().oneshot(req).await + */ + } + + pub enum ReqBody { + Json(serde_json::Value), + + } + + pub async fn run_post( + // payload: Option<&serde_json::Value>, + payload: Option, + uri: &str, + method: axum::http::Method, + has_body: bool, + ) -> Result, axum::http::Error> { + let body = if has_body { + assert_eq!( + true, + payload.is_some(), + "Has request body and payload has data" + ); + // axum::body::Body::from(payload.unwrap().to_string()) + match payload.unwrap() { + ReqBody::Json(val) => { + axum::body::Body::from(val.to_string()) + } + } + } else { + axum::body::Body::empty() + }; + match axum::http::Request::builder() + .method(method) + .uri(uri) + .header( + axum::http::header::CONTENT_TYPE, + "application/json; charset=utf-8", + ) + .header( + axum::http::header::AUTHORIZATION, + super::bearer_auth().await, + ) + .body(body) + { + Ok(t) => Ok(t), + Err(err) => Err(err), + } } }