Refactoring tests #257
+64
-1
@@ -437,13 +437,30 @@ mod tests {
|
|||||||
pub async fn get_queued_coverart(
|
pub async fn get_queued_coverart(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_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::QUEUECOVERART,
|
crate::callers::queue::endpoints::QUEUECOVERART,
|
||||||
coverart_queue_id
|
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()
|
let req = axum::http::Request::builder()
|
||||||
.method(axum::http::Method::GET)
|
.method(axum::http::Method::GET)
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
@@ -456,6 +473,52 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
app.clone().oneshot(req).await
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ReqBody {
|
||||||
|
Json(serde_json::Value),
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run_post(
|
||||||
|
// payload: Option<&serde_json::Value>,
|
||||||
|
payload: Option<ReqBody>,
|
||||||
|
uri: &str,
|
||||||
|
method: axum::http::Method,
|
||||||
|
has_body: bool,
|
||||||
|
) -> Result<axum::http::Request<axum::body::Body>, 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),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user