Adding test
pr CI / Test Suite (pull_request) Successful in 2m1s

This commit is contained in:
phoenix committed 2026-11-21 13:15:01 -05:00
1 parent 9691c36700
commit c5499a3ceb
2 files changed
+102 -22

No files matched your search

+15 -11
View File
@@ -19,9 +19,10 @@ pub mod queue {
use utoipa::ToSchema;
pub mod create_playback_queue {
use serde::{Deserialize, Serialize};
use super::{Deserialize, Serialize, ToSchema};
use super::super::{PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE, PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER};
#[derive(Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
pub struct CreatePlaybackQueueRequest {
pub name: String,
pub device_type: String,
@@ -39,8 +40,8 @@ pub mod queue {
fn valid_device_type(&self) -> bool {
matches!(
self.device_type.as_str(),
super::super::PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER
| super::super::PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE
PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER
| PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE
)
}
}
@@ -57,21 +58,23 @@ pub mod queue {
pub mod response {
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use super::PlaybackQueue;
pub mod create_playback_queue {
use serde::{Deserialize, Serialize};
use super::{Deserialize, Serialize, ToSchema};
use super::PlaybackQueue;
#[derive(Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
pub struct CreatePlaybackQueueResponse {
pub message: String,
pub data: Vec<super::super::PlaybackQueue>,
pub data: Vec<PlaybackQueue>,
}
}
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
pub struct GetPlaybackQueueResponse {
pub message: String,
pub data: Vec<super::PlaybackQueue>,
pub data: Vec<PlaybackQueue>,
}
}
@@ -82,6 +85,7 @@ pub mod queue {
use super::super::super::response as response_message;
use super::super::super::endpoints;
use super::PlaybackQueue;
use super::request::create_playback_queue::CreatePlaybackQueueRequest;
use super::response::create_playback_queue::CreatePlaybackQueueResponse;
use super::request::GetPlaybackQueueParams;
@@ -111,7 +115,7 @@ pub mod queue {
Json<CreatePlaybackQueueResponse>,
) {
let mut response =
super::response::create_playback_queue::CreatePlaybackQueueResponse::default();
CreatePlaybackQueueResponse::default();
if !payload.is_valid() {
response.message = response_message::INVALID.to_string();
@@ -137,7 +141,7 @@ pub mod queue {
response.message = "Already created".to_string();
(StatusCode::OK, Json(response))
} else {
let mut playback_queue = super::PlaybackQueue {
let mut playback_queue = PlaybackQueue {
name: payload.name,
device_type: payload.device_type,
user_id: payload.user_id,
@@ -149,7 +153,7 @@ pub mod queue {
playback_queue.date_created = Some(date_created);
response.data.push(playback_queue);
response.message =
super::super::super::response::SUCCESSFUL.to_string();
response_message::SUCCESSFUL.to_string();
(StatusCode::CREATED, Json(response))
}
+87 -11
View File
@@ -21,7 +21,7 @@ mod tests {
use tower::ServiceExt;
use soaricarus_api::db;
use soaricarus_api::{callers, db};
mod db_mgr {
use std::str::FromStr;
@@ -188,6 +188,12 @@ mod tests {
Body as MultipartBody, Form as MultipartForm,
};
use tower::ServiceExt;
use axum::http;
use axum::response::Response as AxumResponse;
use axum::Router as AxumRouter;
use http::Error as AxumHttpError;
use super::{callers};
pub async fn song_queue_req(
app: &axum::Router,
@@ -278,20 +284,31 @@ mod tests {
app: &axum::Router,
id: &uuid::Uuid,
) -> Result<axum::response::Response, axum::http::Error> {
let raw_uri = String::from(soaricarus_api::callers::queue::endpoints::QUEUESONGDATA);
let raw_uri = String::from(callers::queue::endpoints::QUEUESONGDATA);
let end_index = raw_uri.len() - 4;
let mut uri: String = (&raw_uri[..end_index]).to_string();
uri += &id.to_string();
match run_post(None, &uri, axum::http::Method::GET, false).await {
match run_post(None, &uri, 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(http::Error::from(err)),
},
Err(err) => Err(err),
}
}
pub async fn get_playback_queue(app: &AxumRouter, id: &uuid::Uuid) -> Result<AxumResponse, AxumHttpError> {
let uri = format!("{}?id={}", callers::endpoints::GETPLAYBACKQUEUE, id);
match run_post(None, &uri, http::Method::GET, false).await {
Ok(request) => match app.clone().oneshot(request).await {
Ok(response) => Ok(response),
Err(err) => Err(http::Error::from(err)),
},
Err(err) => Err(err)
}
}
pub async fn upload_coverart_queue_req(
app: &axum::Router,
) -> Result<axum::response::Response, axum::http::Error> {
@@ -2084,12 +2101,16 @@ mod tests {
use futures::StreamExt;
use tower::ServiceExt;
use super::callers;
use super::{db_mgr, init, request, util};
use super::test_data as outer_test_data;
#[tokio::test]
async fn test_get_songs() {
let tm_pool = super::db_mgr::get_pool().await.unwrap();
let db_name = super::db_mgr::generate_db_name().await;
let tm_pool = db_mgr::get_pool().await.unwrap();
let db_name = db_mgr::generate_db_name().await;
match super::db_mgr::create_database(&tm_pool, &db_name).await {
match db_mgr::create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
@@ -2101,16 +2122,16 @@ mod tests {
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 app = init::app(pool).await;
let (id, _, _, _) = test_data::song_id().await.unwrap();
let uri = format!("{}?id={id}", soaricarus_api::callers::endpoints::GETSONGS);
let uri = format!("{}?id={id}", callers::endpoints::GETSONGS);
match app
.clone()
.oneshot(
super::request::run_post(None, &uri, axum::http::Method::GET, false)
request::run_post(None, &uri, axum::http::Method::GET, false)
.await
.unwrap(),
)
@@ -2118,7 +2139,7 @@ mod tests {
{
Ok(response) => {
let resp = super::util::get_resp_data::<
soaricarus_api::callers::song::response::get_songs::Response,
callers::song::response::get_songs::Response,
>(response)
.await;
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
@@ -2675,5 +2696,60 @@ mod tests {
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
#[tokio::test]
async fn test_get_playback_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_mgr::migrations(&pool).await;
let app = init::app(pool).await;
let user_id = outer_test_data::TEST_USER_ID;
let device_type = outer_test_data::DEVICE_TYPE;
let name = outer_test_data::NAME;
use callers::playback::queue::response::create_playback_queue::CreatePlaybackQueueResponse;
use callers::playback::queue::response::GetPlaybackQueueResponse;
match request::create_playback_queue(&app, name, device_type, &user_id).await {
Ok(response) => {
let resp = util::get_resp_data::<
CreatePlaybackQueueResponse
>(response)
.await;
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
let playback_queue = &resp.data[0];
let playback_queue_id = playback_queue.id;
match request::get_playback_queue(&app, &playback_queue_id).await {
Ok(response) => {
let resp = util::get_resp_data::<GetPlaybackQueueResponse>(response).await;
assert_eq!(false, resp.data.is_empty(), "Playback queue was created, but nothing returned");
},
Err(err) => {
eprintln!("Error: {err:?}");
assert!(false, "Error: {err:?}");
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
assert!(false, "Error: {err:?}");
}
}
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
}
}
}