Refactoring tests #257
+16
-3
@@ -484,6 +484,7 @@ mod tests {
|
||||
method: axum::http::Method,
|
||||
has_body: bool,
|
||||
) -> Result<axum::http::Request<axum::body::Body>, axum::http::Error> {
|
||||
let mut content_type = "application/json; charset=utf-8".to_string();
|
||||
let body = if has_body {
|
||||
assert_eq!(
|
||||
true,
|
||||
@@ -491,18 +492,26 @@ mod tests {
|
||||
"Has request body and payload has data"
|
||||
);
|
||||
// axum::body::Body::from(payload.unwrap().to_string())
|
||||
match payload.unwrap() {
|
||||
match payload {
|
||||
Some(p) => match p {
|
||||
ReqBody::Json(val) => 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();
|
||||
// let content_type = form.content_type();
|
||||
content_type = form.content_type();
|
||||
println!("Content: {content_type:?}");
|
||||
let body = MultipartBody::from(form);
|
||||
println!("Streaming");
|
||||
axum::body::Body::from_stream(body)
|
||||
}
|
||||
},
|
||||
None => {
|
||||
eprintln!("This should not empty");
|
||||
axum::body::Body::empty()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
axum::body::Body::empty()
|
||||
@@ -512,7 +521,8 @@ mod tests {
|
||||
.uri(uri)
|
||||
.header(
|
||||
axum::http::header::CONTENT_TYPE,
|
||||
"application/json; charset=utf-8",
|
||||
content_type,
|
||||
// "application/json; charset=utf-8",
|
||||
)
|
||||
.header(
|
||||
axum::http::header::AUTHORIZATION,
|
||||
@@ -798,8 +808,10 @@ mod tests {
|
||||
let app = init::app(pool).await;
|
||||
|
||||
// Send request
|
||||
println!("Trying");
|
||||
match request::song_queue_req(&app).await {
|
||||
Ok(response) => {
|
||||
println!("response: {response:?}");
|
||||
let resp = util::get_resp_data::<
|
||||
crate::callers::queue::song::response::song_queue::Response,
|
||||
>(response)
|
||||
@@ -808,6 +820,7 @@ mod tests {
|
||||
assert_eq!(false, resp.data[0].is_nil(), "Should not be empty");
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Failure!");
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user