Code refactor

This commit is contained in:
kdeng00
2025-04-26 16:51:54 -04:00
parent 70da022a92
commit ba75441eae
+26 -14
View File
@@ -117,7 +117,7 @@ mod tests {
use common_multipart_rfc7578::client::multipart::{ use common_multipart_rfc7578::client::multipart::{
Body as MultipartBody, Form as MultipartForm, Body as MultipartBody, Form as MultipartForm,
}; };
use std::{usize}; use std::usize;
use tower::ServiceExt; use tower::ServiceExt;
mod db_mgr { mod db_mgr {
@@ -202,11 +202,15 @@ mod tests {
.await .await
.layer(axum::Extension(pool)) .layer(axum::Extension(pool))
.layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024)) .layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024))
.layer(tower_http::timeout::TimeoutLayer::new(std::time::Duration::from_secs(300))) .layer(tower_http::timeout::TimeoutLayer::new(
std::time::Duration::from_secs(300),
))
} }
} }
async fn song_queue_req(app: &axum::Router) -> Result<axum::response::Response, std::convert::Infallible> { async fn song_queue_req(
app: &axum::Router,
) -> Result<axum::response::Response, std::convert::Infallible> {
// Create multipart form // Create multipart form
let mut form = MultipartForm::default(); let mut form = MultipartForm::default();
let _ = form.add_file("flac", "tests/Machine_gun/track01.flac"); let _ = form.add_file("flac", "tests/Machine_gun/track01.flac");
@@ -224,13 +228,13 @@ mod tests {
} }
pub async fn get_resp_data<Data>(response: axum::response::Response) -> Data pub async fn get_resp_data<Data>(response: axum::response::Response) -> Data
where where
Data: for<'a>serde::Deserialize<'a> Data: for<'a> serde::Deserialize<'a>,
{ {
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();
serde_json::from_slice(&body).unwrap() serde_json::from_slice(&body).unwrap()
} }
#[tokio::test] #[tokio::test]
@@ -255,7 +259,8 @@ mod tests {
// Send request // Send request
match song_queue_req(&app).await { match song_queue_req(&app).await {
Ok(response) => { Ok(response) => {
let resp = get_resp_data::<crate::callers::song::response::Response>(response).await; 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");
} }
@@ -289,7 +294,8 @@ mod tests {
// Send request // Send request
match song_queue_req(&app).await { match song_queue_req(&app).await {
Ok(response) => { Ok(response) => {
let resp = get_resp_data::<crate::callers::song::response::Response>(response).await; 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");
@@ -302,7 +308,10 @@ mod tests {
match app.clone().oneshot(fetch_req).await { match app.clone().oneshot(fetch_req).await {
Ok(response) => { Ok(response) => {
let resp = get_resp_data::<crate::callers::song::response::fetch_queue_song::Response>(response).await; let resp = get_resp_data::<
crate::callers::song::response::fetch_queue_song::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");
} }
Err(err) => { Err(err) => {
@@ -340,7 +349,8 @@ mod tests {
// Send request // Send request
match song_queue_req(&app).await { match song_queue_req(&app).await {
Ok(response) => { Ok(response) => {
let resp = get_resp_data::<crate::callers::song::response::Response>(response).await; 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");
let new_payload: serde_json::Value = serde_json::json!( let new_payload: serde_json::Value = serde_json::json!(
@@ -372,7 +382,9 @@ mod tests {
.await .await
{ {
Ok(response) => { Ok(response) => {
let resp = get_resp_data::<crate::callers::song::response::Response>(response).await; 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");
} }
Err(err) => { Err(err) => {