Wipe data from coverart queue #136
+232
-13
@@ -371,6 +371,21 @@ mod tests {
|
||||
app.clone().oneshot(req).await
|
||||
}
|
||||
|
||||
|
||||
async fn create_coverart_req(app: &axum::Router, song_id: &uuid::Uuid, coverart_id: &uuid::Uuid) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||
let payload = serde_json::json!({
|
||||
"song_id": song_id,
|
||||
"coverart_queue_id": coverart_id
|
||||
});
|
||||
let req = axum::http::Request::builder()
|
||||
.method(axum::http::Method::POST)
|
||||
.uri(crate::callers::endpoints::CREATECOVERART)
|
||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||
.body(axum::body::Body::from(payload.to_string()))
|
||||
.unwrap();
|
||||
app.clone().oneshot(req).await
|
||||
}
|
||||
|
||||
async fn create_song_req(
|
||||
app: &axum::Router,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
@@ -1457,19 +1472,7 @@ mod tests {
|
||||
"Should not be empty"
|
||||
);
|
||||
|
||||
let payload = serde_json::json!({
|
||||
"song_id": song_id,
|
||||
"coverart_queue_id": resp_coverart_id,
|
||||
});
|
||||
|
||||
match app.clone().oneshot(
|
||||
axum::http::Request::builder()
|
||||
.method(axum::http::Method::POST)
|
||||
.uri(crate::callers::endpoints::CREATECOVERART)
|
||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||
.body(axum::body::Body::from(payload.to_string()))
|
||||
.unwrap()
|
||||
).await {
|
||||
match create_coverart_req(&app, &song_id, &resp_coverart_id).await {
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::create_coverart::Response,
|
||||
@@ -1643,5 +1646,221 @@ mod tests {
|
||||
// TODO: Complete test
|
||||
#[tokio::test]
|
||||
async fn test_wipe_data_from_coverart_queue() {
|
||||
let tm_pool = db_mgr::get_pool().await.unwrap();
|
||||
let db_name = db_mgr::generate_db_name().await;
|
||||
|
||||
match db_mgr::create_database(&tm_pool, &db_name).await {
|
||||
Ok(_) => {
|
||||
println!("Success");
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
|
||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||
db::migrations(&pool).await;
|
||||
|
||||
let app = init::app(pool).await;
|
||||
|
||||
// Send request
|
||||
match song_queue_req(&app).await {
|
||||
Ok(response) => {
|
||||
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[0].is_nil(), "Should not be empty");
|
||||
let song_queue_id = resp.data[0];
|
||||
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
||||
|
||||
match queue_metadata_req(&app, &resp.data[0]).await {
|
||||
Ok(response) => {
|
||||
let resp =
|
||||
get_resp_data::<crate::callers::song::response::Response>(response)
|
||||
.await;
|
||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||
|
||||
let id = resp.data[0];
|
||||
|
||||
match fetch_metadata_queue_req(&app, &id).await {
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::metadata::response::fetch_metadata::Response,
|
||||
>(response)
|
||||
.await;
|
||||
assert_eq!(false, resp.data.is_empty(), "Data should not be empty");
|
||||
let song_q_id = resp.data[0].song_queue_id;
|
||||
|
||||
match create_song_req(&app, &song_q_id).await {
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<crate::callers::song::response::create_metadata::Response>(response).await;
|
||||
assert_eq!(
|
||||
false,
|
||||
resp.data.is_empty(),
|
||||
"No songs found, Response {:?}",
|
||||
resp
|
||||
);
|
||||
let song = &resp.data[0];
|
||||
let song_id = song.id;
|
||||
assert_eq!(
|
||||
false,
|
||||
song_id.is_nil(),
|
||||
"Song id should not be nil {:?}",
|
||||
song
|
||||
);
|
||||
|
||||
eprintln!("Song: {:?}", song);
|
||||
|
||||
match upload_coverart_queue_req(&app).await {
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::Response,
|
||||
>(
|
||||
response
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
false,
|
||||
resp.data.is_empty(),
|
||||
"Should not be empty"
|
||||
);
|
||||
let coverart_id = resp.data[0];
|
||||
assert_eq!(
|
||||
false,
|
||||
coverart_id.is_nil(),
|
||||
"Should not be empty"
|
||||
);
|
||||
|
||||
match coverart_queue_song_queue_link_req(
|
||||
&app,
|
||||
&coverart_id,
|
||||
&song_queue_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::link::Response,
|
||||
>(response)
|
||||
.await;
|
||||
assert_eq!(
|
||||
false,
|
||||
resp.data.is_empty(),
|
||||
"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!(
|
||||
false,
|
||||
resp_coverart_id.is_nil(),
|
||||
"Should not be empty"
|
||||
);
|
||||
assert_eq!(
|
||||
false,
|
||||
resp_song_queue_id.is_nil(),
|
||||
"Should not be empty"
|
||||
);
|
||||
|
||||
match get_queued_coverart(
|
||||
&app,
|
||||
&resp_coverart_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::fetch_coverart_no_data::Response,
|
||||
>(response)
|
||||
.await;
|
||||
assert_eq!(
|
||||
false,
|
||||
resp.data.is_empty(),
|
||||
"Should not be empty"
|
||||
);
|
||||
|
||||
match create_coverart_req(&app, &song_id, &resp_coverart_id).await {
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::create_coverart::Response,
|
||||
>(response)
|
||||
.await;
|
||||
assert_eq!(
|
||||
false,
|
||||
resp.data.is_empty(),
|
||||
"Should not be empty"
|
||||
);
|
||||
|
||||
let payload = serde_json::json!({
|
||||
"coverart_queue_id": resp_coverart_id
|
||||
});
|
||||
|
||||
match app.clone().oneshot(
|
||||
axum::http::Request::builder()
|
||||
.method(axum::http::Method::PATCH)
|
||||
.uri(crate::callers::endpoints::QUEUECOVERARTDATAWIPE)
|
||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||
.body(axum::body::Body::from(payload.to_string()))
|
||||
.unwrap()
|
||||
).await {
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::wipe_data_from_coverart_queue::Response,
|
||||
>(response)
|
||||
.await;
|
||||
assert_eq!(
|
||||
false,
|
||||
resp.data.is_empty(),
|
||||
"Should not be empty"
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
};
|
||||
|
||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user