Refactoring tests #141
+51
-78
@@ -432,11 +432,14 @@ mod tests {
|
|||||||
// use tower::ServiceExt;
|
// use tower::ServiceExt;
|
||||||
|
|
||||||
// Flow for queueing song
|
// Flow for queueing song
|
||||||
pub async fn queue_song_flow(app: &axum::Router) -> Result<axum::response::Response, std::convert::Infallible> {
|
pub async fn queue_song_flow(
|
||||||
|
app: &axum::Router,
|
||||||
|
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
match super::song_queue_req(&app).await {
|
match super::song_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp =
|
||||||
super::get_resp_data::<crate::callers::song::response::Response>(response).await;
|
super::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 song_queue_id = resp.data[0];
|
let song_queue_id = resp.data[0];
|
||||||
@@ -444,50 +447,39 @@ mod tests {
|
|||||||
|
|
||||||
match super::queue_metadata_req(&app, &resp.data[0]).await {
|
match super::queue_metadata_req(&app, &resp.data[0]).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp = super::get_resp_data::<
|
||||||
super::get_resp_data::<crate::callers::song::response::Response>(response)
|
crate::callers::song::response::Response,
|
||||||
.await;
|
>(response)
|
||||||
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
|
|
||||||
let id = resp.data[0];
|
let id = resp.data[0];
|
||||||
|
|
||||||
match super::fetch_metadata_queue_req(&app, &id).await {
|
match super::fetch_metadata_queue_req(&app, &id).await {
|
||||||
Ok(response) => {
|
Ok(response) => Ok(response),
|
||||||
Ok(response)
|
Err(err) => Err(err),
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => Err(err),
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn queue_coverart_flow(app: &axum::Router, song_queue_id: &uuid::Uuid) -> Result<axum::response::Response, std::convert::Infallible> {
|
pub async fn queue_coverart_flow(
|
||||||
|
app: &axum::Router,
|
||||||
|
song_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
match super::upload_coverart_queue_req(&app).await {
|
match super::upload_coverart_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = super::get_resp_data::<
|
let resp =
|
||||||
crate::callers::coverart::response::Response,
|
super::get_resp_data::<crate::callers::coverart::response::Response>(
|
||||||
>(
|
response,
|
||||||
response
|
)
|
||||||
)
|
.await;
|
||||||
.await;
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
assert_eq!(
|
|
||||||
false,
|
|
||||||
resp.data.is_empty(),
|
|
||||||
"Should not be empty"
|
|
||||||
);
|
|
||||||
let coverart_id = resp.data[0];
|
let coverart_id = resp.data[0];
|
||||||
assert_eq!(
|
assert_eq!(false, coverart_id.is_nil(), "Should not be empty");
|
||||||
false,
|
|
||||||
coverart_id.is_nil(),
|
|
||||||
"Should not be empty"
|
|
||||||
);
|
|
||||||
|
|
||||||
match super::coverart_queue_song_queue_link_req(
|
match super::coverart_queue_song_queue_link_req(
|
||||||
&app,
|
&app,
|
||||||
@@ -501,39 +493,16 @@ mod tests {
|
|||||||
crate::callers::coverart::response::link::Response,
|
crate::callers::coverart::response::link::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
false,
|
let resp_coverart_id = resp.data[0].coverart_id;
|
||||||
resp.data.is_empty(),
|
let resp_song_queue_id = resp.data[0].song_queue_id;
|
||||||
"Should not be empty"
|
|
||||||
);
|
|
||||||
let resp_coverart_id =
|
|
||||||
resp.data[0].coverart_id;
|
|
||||||
let resp_song_queue_id =
|
|
||||||
resp.data[0].song_queue_id;
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(false, resp_coverart_id.is_nil(), "Should not be empty");
|
||||||
false,
|
assert_eq!(false, resp_song_queue_id.is_nil(), "Should not be empty");
|
||||||
resp_coverart_id.is_nil(),
|
|
||||||
"Should not be empty"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
false,
|
|
||||||
resp_song_queue_id.is_nil(),
|
|
||||||
"Should not be empty"
|
|
||||||
);
|
|
||||||
|
|
||||||
match super::get_queued_coverart(
|
match super::get_queued_coverart(&app, &resp_coverart_id).await {
|
||||||
&app,
|
Ok(response) => Ok(response),
|
||||||
&resp_coverart_id,
|
Err(err) => Err(err),
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(response) => {
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1786,10 +1755,12 @@ mod tests {
|
|||||||
assert_eq!(false, resp.data.is_empty(), "Data should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Data should not be empty");
|
||||||
let song_queue_id = resp.data[0].song_queue_id;
|
let song_queue_id = resp.data[0].song_queue_id;
|
||||||
|
|
||||||
|
|
||||||
match create_song_req(&app, &song_queue_id).await {
|
match create_song_req(&app, &song_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<crate::callers::song::response::create_metadata::Response>(response).await;
|
let resp = get_resp_data::<
|
||||||
|
crate::callers::song::response::create_metadata::Response,
|
||||||
|
>(response)
|
||||||
|
.await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
false,
|
false,
|
||||||
resp.data.is_empty(),
|
resp.data.is_empty(),
|
||||||
@@ -1813,11 +1784,7 @@ mod tests {
|
|||||||
crate::callers::coverart::response::fetch_coverart_no_data::Response,
|
crate::callers::coverart::response::fetch_coverart_no_data::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
false,
|
|
||||||
resp.data.is_empty(),
|
|
||||||
"Should not be empty"
|
|
||||||
);
|
|
||||||
|
|
||||||
let resp_coverart_queue_id = resp.data[0].id;
|
let resp_coverart_queue_id = resp.data[0].id;
|
||||||
|
|
||||||
@@ -1825,14 +1792,21 @@ mod tests {
|
|||||||
"coverart_queue_id": resp_coverart_queue_id
|
"coverart_queue_id": resp_coverart_queue_id
|
||||||
});
|
});
|
||||||
|
|
||||||
match app.clone().oneshot(
|
match app
|
||||||
axum::http::Request::builder()
|
.clone()
|
||||||
.method(axum::http::Method::PATCH)
|
.oneshot(
|
||||||
.uri(crate::callers::endpoints::QUEUECOVERARTDATAWIPE)
|
axum::http::Request::builder()
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
.method(axum::http::Method::PATCH)
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
.uri(crate::callers::endpoints::QUEUECOVERARTDATAWIPE)
|
||||||
.unwrap()
|
.header(
|
||||||
).await {
|
axum::http::header::CONTENT_TYPE,
|
||||||
|
"application/json",
|
||||||
|
)
|
||||||
|
.body(axum::body::Body::from(payload.to_string()))
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::wipe_data_from_coverart_queue::Response,
|
crate::callers::coverart::response::wipe_data_from_coverart_queue::Response,
|
||||||
@@ -1864,7 +1838,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user