Added code to get response content
This commit is contained in:
+34
-15
@@ -206,6 +206,36 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn song_queue_req(app: &axum::Router) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
|
// Create multipart form
|
||||||
|
let mut form = MultipartForm::default();
|
||||||
|
let _ = form.add_file("flac", "tests/Machine_gun/track01.flac");
|
||||||
|
|
||||||
|
// Create request
|
||||||
|
let content_type = form.content_type();
|
||||||
|
let body = MultipartBody::from(form);
|
||||||
|
let req = axum::http::Request::builder()
|
||||||
|
.method(axum::http::Method::POST)
|
||||||
|
.uri(crate::callers::endpoints::QUEUESONG)
|
||||||
|
.header(axum::http::header::CONTENT_TYPE, content_type)
|
||||||
|
.body(axum::body::Body::from_stream(body))
|
||||||
|
.unwrap();
|
||||||
|
app.clone().oneshot(req).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_resp_data<Data>(response: axum::response::Response) -> Data
|
||||||
|
|
||||||
|
where
|
||||||
|
Data: for<'a>serde::Deserialize<'a>
|
||||||
|
{
|
||||||
|
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let resp: Data =
|
||||||
|
serde_json::from_slice(&body).unwrap();
|
||||||
|
resp
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_song_queue() {
|
async fn test_song_queue() {
|
||||||
let tm_pool = db_mgr::get_pool().await.unwrap();
|
let tm_pool = db_mgr::get_pool().await.unwrap();
|
||||||
@@ -225,29 +255,18 @@ mod tests {
|
|||||||
|
|
||||||
let app = init::app(pool).await;
|
let app = init::app(pool).await;
|
||||||
|
|
||||||
// Create multipart form
|
|
||||||
let mut form = MultipartForm::default();
|
|
||||||
let _ = form.add_file("flac", "tests/Machine_gun/track01.flac");
|
|
||||||
|
|
||||||
// Create request
|
|
||||||
let content_type = form.content_type();
|
|
||||||
let body = MultipartBody::from(form);
|
|
||||||
let req = axum::http::Request::builder()
|
|
||||||
.method(axum::http::Method::POST)
|
|
||||||
.uri(crate::callers::endpoints::QUEUESONG)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
|
||||||
.body(axum::body::Body::from_stream(body))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
match app.oneshot(req).await {
|
match song_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
|
/*
|
||||||
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
|
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("Body: {:?}", body);
|
println!("Body: {:?}", body);
|
||||||
let resp: crate::callers::song::response::Response =
|
let resp: crate::callers::song::response::Response =
|
||||||
serde_json::from_slice(&body).unwrap();
|
serde_json::from_slice(&body).unwrap();
|
||||||
|
*/
|
||||||
|
let resp = get_resp_data::<crate::callers::song::response::Response>(response).await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
assert_eq!(false, resp.data[0].is_nil(), "Should not be empty");
|
assert_eq!(false, resp.data[0].is_nil(), "Should not be empty");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user