This commit is contained in:
1 file changed
+83
+83
@@ -145,6 +145,11 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
mod test_data {
|
||||
pub const DEVICE_TYPE: &str = "BROWSER";
|
||||
pub const NAME: &str = "DougDimmaDome Browser Queue";
|
||||
}
|
||||
|
||||
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
||||
|
||||
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
||||
@@ -444,6 +449,31 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_playback_queue(
|
||||
app: &axum::Router,
|
||||
name: &str,
|
||||
device_type: &str,
|
||||
user_id: &uuid::Uuid,
|
||||
) -> Result<axum::response::Response, axum::http::Error> {
|
||||
let uri = soaricarus_api::callers::endpoints::CREATEPLAYBACKQUEUE;
|
||||
let payload =
|
||||
super::payload_data::create_playback_queue(name, device_type, user_id).await;
|
||||
match run_post(
|
||||
Some(ReqBody::Json(payload)),
|
||||
uri,
|
||||
axum::http::Method::POST,
|
||||
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 enum ReqBody {
|
||||
Json(serde_json::Value),
|
||||
Multipart((String, String)),
|
||||
@@ -819,6 +849,18 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn create_playback_queue(
|
||||
name: &str,
|
||||
device_type: &str,
|
||||
user_id: &uuid::Uuid,
|
||||
) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
"name": name,
|
||||
"device_type": device_type,
|
||||
"user_id": user_id
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn link_user_to_queued_song(
|
||||
song_queue_id: &uuid::Uuid,
|
||||
user_id: &uuid::Uuid,
|
||||
@@ -2036,6 +2078,8 @@ mod tests {
|
||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
|
||||
// NOTE: This was probably done so the tests in this module run after
|
||||
// all the other tests finished
|
||||
pub mod zzz_after_song_queue {
|
||||
use futures::StreamExt;
|
||||
use tower::ServiceExt;
|
||||
@@ -2592,5 +2636,44 @@ mod tests {
|
||||
|
||||
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_create_playback_queue() {
|
||||
let tm_pool = super::db_mgr::get_pool().await.unwrap();
|
||||
let db_name = super::db_mgr::generate_db_name().await;
|
||||
|
||||
match super::db_mgr::create_database(&tm_pool, &db_name).await {
|
||||
Ok(_) => {
|
||||
println!("Success");
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
|
||||
let pool = super::db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||
super::db_mgr::migrations(&pool).await;
|
||||
|
||||
let app = super::init::app(pool).await;
|
||||
let user_id = super::TEST_USER_ID;
|
||||
let device_type = super::test_data::DEVICE_TYPE;
|
||||
let name = super::test_data::NAME;
|
||||
|
||||
match super::request::create_playback_queue(&app, name, device_type, &user_id).await {
|
||||
Ok(response) => {
|
||||
let resp = super::util::get_resp_data::<
|
||||
soaricarus_api::callers::playback::queue::response::create_playback_queue::CreatePlaybackQueueResponse
|
||||
>(response)
|
||||
.await;
|
||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user