Refactoring tests (#257)
soaricarus_api CI / Rustfmt (push) Successful in 4m43s
soaricarus_api CI / Check (push) Successful in 5m26s
soaricarus_api CI / Test Suite (push) Successful in 6m4s
soaricarus_api CI / Clippy (push) Successful in 6m54s
soaricarus_api CI / build (push) Successful in 8m54s
soaricarus_api CI / Rustfmt (push) Successful in 4m43s
soaricarus_api CI / Check (push) Successful in 5m26s
soaricarus_api CI / Test Suite (push) Successful in 6m4s
soaricarus_api CI / Clippy (push) Successful in 6m54s
soaricarus_api CI / build (push) Successful in 8m54s
Reviewed-on: #257
This commit was merged in pull request #257.
This commit is contained in:
Generated
+2
-2
@@ -1937,8 +1937,8 @@ checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "labyrinth"
|
name = "labyrinth"
|
||||||
version = "0.0.2"
|
version = "0.0.4"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/labyrinth.git?tag=v0.0.2-1-84f98521c8-928#84f98521c8c98693e422db48eb0aa7c124c2586b"
|
source = "git+ssh://git@git.kundeng.us/phoenix/labyrinth.git?tag=v0.0.4#f406ed196145bb667587c13f4fd0866a1fa6e915"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-config",
|
"aws-config",
|
||||||
"aws-sdk-s3",
|
"aws-sdk-s3",
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
|||||||
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.1-main-b690995806-680" }
|
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.1-main-b690995806-680" }
|
||||||
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" }
|
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" }
|
||||||
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" }
|
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" }
|
||||||
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.2-1-84f98521c8-928" }
|
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.4" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
common-multipart-rfc7578 = { version = "0.7.0" }
|
common-multipart-rfc7578 = { version = "0.7.0" }
|
||||||
|
|||||||
@@ -212,6 +212,31 @@ pub mod endpoint {
|
|||||||
match lr.upload(&file_path, &data).await {
|
match lr.upload(&file_path, &data).await {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
println!("Result: {res:?}");
|
println!("Result: {res:?}");
|
||||||
|
|
||||||
|
println!("Downloading file");
|
||||||
|
match lr.download(&file_path).await {
|
||||||
|
Ok(res) => {
|
||||||
|
if res.is_empty() {
|
||||||
|
println!("This should not be empty");
|
||||||
|
} else {
|
||||||
|
println!("Size: {:?}", res.len());
|
||||||
|
println!("Going to delete file");
|
||||||
|
|
||||||
|
match lr.delete(&file_path).await {
|
||||||
|
Ok(res) => {
|
||||||
|
println!("Result: {res:?}");
|
||||||
|
println!("Deleted");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => match err {
|
Err(err) => match err {
|
||||||
labyrinth::Error::Info(err_str) => {
|
labyrinth::Error::Info(err_str) => {
|
||||||
|
|||||||
+278
-278
@@ -25,9 +25,6 @@ async fn main() {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use common_multipart_rfc7578::client::multipart::{
|
|
||||||
Body as MultipartBody, Form as MultipartForm,
|
|
||||||
};
|
|
||||||
use tower::ServiceExt;
|
use tower::ServiceExt;
|
||||||
|
|
||||||
use crate::db;
|
use crate::db;
|
||||||
@@ -193,269 +190,318 @@ mod tests {
|
|||||||
|
|
||||||
pub async fn song_queue_req(
|
pub async fn song_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
// Create multipart form
|
// Create multipart form
|
||||||
let mut form = MultipartForm::default();
|
match run_post(
|
||||||
let _ = form.add_file("flac", "tests/I/track01.flac");
|
Some(ReqBody::Multipart((
|
||||||
|
"flac".to_string(),
|
||||||
// Create request
|
"tests/I/track01.flac".to_string(),
|
||||||
let content_type = form.content_type();
|
))),
|
||||||
let body = MultipartBody::from(form);
|
crate::callers::queue::endpoints::QUEUESONG,
|
||||||
let req = axum::http::Request::builder()
|
axum::http::Method::POST,
|
||||||
.method(axum::http::Method::POST)
|
true,
|
||||||
.uri(crate::callers::queue::endpoints::QUEUESONG)
|
)
|
||||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
.await
|
||||||
.header(
|
{
|
||||||
axum::http::header::AUTHORIZATION,
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
super::bearer_auth().await,
|
Ok(response) => Ok(response),
|
||||||
)
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.body(axum::body::Body::from_stream(body))
|
},
|
||||||
.unwrap();
|
Err(err) => Err(err),
|
||||||
app.clone().oneshot(req).await
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn song_queue_link_req(
|
pub async fn song_queue_link_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
user_id: &uuid::Uuid,
|
user_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload =
|
let payload =
|
||||||
super::payload_data::link_user_to_queued_song(song_queue_id, user_id).await;
|
super::payload_data::link_user_to_queued_song(song_queue_id, user_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::PATCH)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::queue::endpoints::QUEUESONGLINKUSERID)
|
crate::callers::queue::endpoints::QUEUESONGLINKUSERID,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::PATCH,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
app.clone().oneshot(req).await
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_queue_req(
|
pub async fn fetch_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let fetch_req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::GET)
|
None,
|
||||||
.uri(crate::callers::queue::endpoints::NEXTQUEUESONG)
|
crate::callers::queue::endpoints::NEXTQUEUESONG,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::GET,
|
||||||
.header(
|
false,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::empty())
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
app.clone().oneshot(fetch_req).await
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_metadata_queue_req(
|
pub async fn fetch_metadata_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let uri = format!(
|
let uri = format!(
|
||||||
"{}?id={}",
|
"{}?id={}",
|
||||||
crate::callers::queue::endpoints::QUEUEMETADATA,
|
crate::callers::queue::endpoints::QUEUEMETADATA,
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(None, &uri, axum::http::Method::GET, false).await {
|
||||||
.method(axum::http::Method::GET)
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.uri(uri)
|
Ok(response) => Ok(response),
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.header(
|
},
|
||||||
axum::http::header::AUTHORIZATION,
|
Err(err) => Err(err),
|
||||||
super::bearer_auth().await,
|
}
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_queue_data_req(
|
pub async fn fetch_queue_data_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let raw_uri = String::from(crate::callers::queue::endpoints::QUEUESONGDATA);
|
let raw_uri = String::from(crate::callers::queue::endpoints::QUEUESONGDATA);
|
||||||
let end_index = raw_uri.len() - 4;
|
let end_index = raw_uri.len() - 4;
|
||||||
let mut uri: String = (&raw_uri[..end_index]).to_string();
|
let mut uri: String = (&raw_uri[..end_index]).to_string();
|
||||||
uri += &id.to_string();
|
uri += &id.to_string();
|
||||||
let req = axum::http::Request::builder()
|
|
||||||
.method(axum::http::Method::GET)
|
|
||||||
.uri(uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::CONTENT_TYPE,
|
|
||||||
simeta::detection::song::constants::mime::FLAC,
|
|
||||||
)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
match run_post(None, &uri, axum::http::Method::GET, false).await {
|
||||||
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upload_coverart_queue_req(
|
pub async fn upload_coverart_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let mut form = MultipartForm::default();
|
match run_post(
|
||||||
let _ = form.add_file(
|
Some(ReqBody::Multipart((
|
||||||
simeta::detection::coverart::constants::JPEG_TYPE,
|
simeta::detection::coverart::constants::JPEG_TYPE.to_string(),
|
||||||
"tests/I/Coverart-1.jpg",
|
"tests/I/Coverart-1.jpg".to_string(),
|
||||||
);
|
))),
|
||||||
|
crate::callers::queue::endpoints::QUEUECOVERART,
|
||||||
// Create request
|
axum::http::Method::POST,
|
||||||
let content_type = form.content_type();
|
true,
|
||||||
let body = MultipartBody::from(form);
|
)
|
||||||
|
.await
|
||||||
let req = axum::http::Request::builder()
|
{
|
||||||
.method(axum::http::Method::POST)
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.uri(crate::callers::queue::endpoints::QUEUECOVERART)
|
Ok(response) => Ok(response),
|
||||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.header(
|
},
|
||||||
axum::http::header::AUTHORIZATION,
|
Err(err) => Err(err),
|
||||||
super::bearer_auth().await,
|
}
|
||||||
)
|
|
||||||
.body(axum::body::Body::from_stream(body))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn queue_metadata_req(
|
pub async fn queue_metadata_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = super::payload_data::queue_metadata(&song_queue_id).await;
|
let payload = super::payload_data::queue_metadata(&song_queue_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::POST)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::queue::endpoints::QUEUEMETADATA)
|
crate::callers::queue::endpoints::QUEUEMETADATA,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::POST,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
app.clone().oneshot(req).await
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn coverart_queue_song_queue_link_req(
|
pub async fn coverart_queue_song_queue_link_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
coverart_id: &uuid::Uuid,
|
coverart_id: &uuid::Uuid,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = super::payload_data::link_queued_coverart_to_queued_song(
|
let payload = super::payload_data::link_queued_coverart_to_queued_song(
|
||||||
song_queue_id,
|
song_queue_id,
|
||||||
coverart_id,
|
coverart_id,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
let req = axum::http::Request::builder()
|
|
||||||
.method(axum::http::Method::PATCH)
|
|
||||||
.uri(crate::callers::queue::endpoints::QUEUECOVERARTLINK)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
match run_post(
|
||||||
|
Some(ReqBody::Json(payload)),
|
||||||
|
crate::callers::queue::endpoints::QUEUECOVERARTLINK,
|
||||||
|
axum::http::Method::PATCH,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_coverart_req(
|
pub async fn create_coverart_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_id: &uuid::Uuid,
|
song_id: &uuid::Uuid,
|
||||||
coverart_id: &uuid::Uuid,
|
coverart_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = super::payload_data::create_coverart(song_id, coverart_id).await;
|
let payload = super::payload_data::create_coverart(song_id, coverart_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::POST)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::endpoints::CREATECOVERART)
|
crate::callers::endpoints::CREATECOVERART,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::POST,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
app.clone().oneshot(req).await
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_song_req(
|
pub async fn create_song_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
user_id: &uuid::Uuid,
|
user_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = super::payload_data::create_song(song_queue_id, user_id).await;
|
let payload = super::payload_data::create_song(song_queue_id, user_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::POST)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::endpoints::CREATESONG)
|
crate::callers::endpoints::CREATESONG,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::POST,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
app.clone().oneshot(req).await
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_song_queue_status_req(
|
pub async fn update_song_queue_status_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload =
|
let payload =
|
||||||
super::payload_data::update_song_queue_status_to_ready(song_queue_id).await;
|
super::payload_data::update_song_queue_status_to_ready(song_queue_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::PATCH)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::queue::endpoints::QUEUESONG)
|
crate::callers::queue::endpoints::QUEUESONG,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::PATCH,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
app.clone().oneshot(req).await
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_queued_coverart(
|
pub async fn get_queued_coverart(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let uri = format!(
|
let uri = format!(
|
||||||
"{}?id={}",
|
"{}?id={}",
|
||||||
crate::callers::queue::endpoints::QUEUECOVERART,
|
crate::callers::queue::endpoints::QUEUECOVERART,
|
||||||
coverart_queue_id
|
coverart_queue_id
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(None, &uri, axum::http::Method::GET, false).await {
|
||||||
.method(axum::http::Method::GET)
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ReqBody {
|
||||||
|
Json(serde_json::Value),
|
||||||
|
Multipart((String, String)),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run_post(
|
||||||
|
payload: Option<ReqBody>,
|
||||||
|
uri: &str,
|
||||||
|
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,
|
||||||
|
payload.is_some(),
|
||||||
|
"Has request body and payload has data"
|
||||||
|
);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
content_type = form.content_type();
|
||||||
|
let body = MultipartBody::from(form);
|
||||||
|
axum::body::Body::from_stream(body)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
eprintln!("This should not empty");
|
||||||
|
axum::body::Body::empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
axum::body::Body::empty()
|
||||||
|
};
|
||||||
|
match axum::http::Request::builder()
|
||||||
|
.method(method)
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
.header(axum::http::header::CONTENT_TYPE, content_type)
|
||||||
.header(
|
.header(
|
||||||
axum::http::header::AUTHORIZATION,
|
axum::http::header::AUTHORIZATION,
|
||||||
super::bearer_auth().await,
|
super::bearer_auth().await,
|
||||||
)
|
)
|
||||||
.body(axum::body::Body::empty())
|
.body(body)
|
||||||
.unwrap();
|
{
|
||||||
|
Ok(t) => Ok(t),
|
||||||
app.clone().oneshot(req).await
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,7 +509,7 @@ mod tests {
|
|||||||
// Flow for queueing song
|
// Flow for queueing song
|
||||||
pub async fn queue_song_flow(
|
pub async fn queue_song_flow(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<(axum::response::Response, uuid::Uuid), std::convert::Infallible> {
|
) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> {
|
||||||
match super::request::song_queue_req(&app).await {
|
match super::request::song_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = super::util::get_resp_data::<
|
let resp = super::util::get_resp_data::<
|
||||||
@@ -506,6 +552,7 @@ mod tests {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
@@ -519,7 +566,7 @@ mod tests {
|
|||||||
pub async fn queue_coverart_flow(
|
pub async fn queue_coverart_flow(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
match super::request::upload_coverart_queue_req(&app).await {
|
match super::request::upload_coverart_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = super::util::get_resp_data::<
|
let resp = super::util::get_resp_data::<
|
||||||
@@ -555,15 +602,17 @@ mod tests {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns coverart response and song_queue_id
|
// Returns coverart response and song_queue_id
|
||||||
pub async fn queue_song_and_coverart_flow(
|
pub async fn queue_song_and_coverart_flow(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<(axum::response::Response, uuid::Uuid), std::convert::Infallible> {
|
) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> {
|
||||||
match queue_song_flow(&app).await {
|
match queue_song_flow(&app).await {
|
||||||
Ok((song_response, user_id)) => {
|
Ok((song_response, user_id)) => {
|
||||||
let resp = super::util::get_resp_data::<
|
let resp = super::util::get_resp_data::<
|
||||||
@@ -931,13 +980,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
let songpath = song.song_path().unwrap();
|
let songpath = song.song_path().unwrap();
|
||||||
|
|
||||||
let mut form = MultipartForm::default();
|
|
||||||
let _ = form.add_file("flac", &songpath);
|
|
||||||
|
|
||||||
// Create request
|
|
||||||
let content_type = form.content_type();
|
|
||||||
let body = MultipartBody::from(form);
|
|
||||||
|
|
||||||
let raw_uri =
|
let raw_uri =
|
||||||
String::from(crate::callers::queue::endpoints::QUEUESONGUPDATE);
|
String::from(crate::callers::queue::endpoints::QUEUESONGUPDATE);
|
||||||
let end_index = raw_uri.len() - 5;
|
let end_index = raw_uri.len() - 5;
|
||||||
@@ -951,16 +993,17 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
request::run_post(
|
||||||
.method(axum::http::Method::PATCH)
|
Some(request::ReqBody::Multipart((
|
||||||
.uri(uri)
|
"flac".to_string(),
|
||||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
songpath,
|
||||||
.header(
|
))),
|
||||||
axum::http::header::AUTHORIZATION,
|
&uri,
|
||||||
bearer_auth().await,
|
axum::http::Method::PATCH,
|
||||||
)
|
true,
|
||||||
.body(axum::body::Body::from_stream(body))
|
)
|
||||||
.unwrap(),
|
.await
|
||||||
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -1441,16 +1484,14 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
request::run_post(
|
||||||
.method(axum::http::Method::GET)
|
None,
|
||||||
.uri(uri)
|
&uri,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "image/jpeg")
|
axum::http::Method::GET,
|
||||||
.header(
|
false,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
bearer_auth().await,
|
.await
|
||||||
)
|
.unwrap(),
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -1648,6 +1689,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -1715,13 +1759,14 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
request::run_post(
|
||||||
.method(axum::http::Method::PATCH)
|
Some(request::ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::queue::endpoints::QUEUESONGDATAWIPE)
|
crate::callers::queue::endpoints::QUEUESONGDATAWIPE,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::PATCH,
|
||||||
.header(axum::http::header::AUTHORIZATION, bearer_auth().await)
|
true,
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
)
|
||||||
.unwrap(),
|
.await
|
||||||
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -1833,19 +1878,14 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
request::run_post(
|
||||||
.method(axum::http::Method::PATCH)
|
Some(request::ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::queue::endpoints::QUEUECOVERARTDATAWIPE)
|
crate::callers::queue::endpoints::QUEUECOVERARTDATAWIPE,
|
||||||
.header(
|
axum::http::Method::PATCH,
|
||||||
axum::http::header::CONTENT_TYPE,
|
true,
|
||||||
"application/json",
|
)
|
||||||
)
|
.await
|
||||||
.header(
|
.unwrap(),
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -1913,15 +1953,8 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false)
|
||||||
.method(axum::http::Method::GET)
|
.await
|
||||||
.uri(uri)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -1970,15 +2003,8 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false)
|
||||||
.method(axum::http::Method::GET)
|
.await
|
||||||
.uri(uri)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -2059,14 +2085,8 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false)
|
||||||
.method(axum::http::Method::GET)
|
.await
|
||||||
.uri(&uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -2119,14 +2139,8 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false)
|
||||||
.method(axum::http::Method::GET)
|
.await
|
||||||
.uri(&uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -2181,14 +2195,8 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false)
|
||||||
.method(axum::http::Method::GET)
|
.await
|
||||||
.uri(&uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -2308,14 +2316,8 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::DELETE, false)
|
||||||
.method(axum::http::Method::DELETE)
|
.await
|
||||||
.uri(&uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -2380,16 +2382,14 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(
|
||||||
.method(axum::http::Method::GET)
|
None,
|
||||||
.uri(crate::callers::endpoints::GETALLSONGS)
|
crate::callers::endpoints::GETALLSONGS,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::GET,
|
||||||
.header(
|
false,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
.unwrap(),
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user