Adding tests
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Test Suite (pull_request) Successful in 57s

This commit is contained in:
2026-06-17 15:45:52 -04:00
parent c9d3bef42a
commit f2c2642969
+94 -23
View File
@@ -240,7 +240,14 @@ mod request {
"id": id
});
match run_post(Some(&payload), textsender_api::caller::endpoints::UPDATE_CONTACT_NAME, axum::http::Method::PATCH, true).await {
match run_post(
Some(&payload),
textsender_api::caller::endpoints::UPDATE_CONTACT_NAME,
axum::http::Method::PATCH,
true,
)
.await
{
Ok(req) => match app.clone().oneshot(req).await {
Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
@@ -250,7 +257,7 @@ mod request {
}
pub mod message {
use tower::ServiceExt;
use tower::ServiceExt;
pub async fn create_message(
app: &axum::Router,
@@ -260,32 +267,39 @@ mod request {
"user_id": super::super::TEST_USER_ID,
});
match super::run_post(Some(&payload), textsender_api::caller::endpoints::ADD_MESSAGE, axum::http::Method::POST, true).await {
Ok(req) => match app.clone().oneshot(req).await {
Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
match super::run_post(
Some(&payload),
textsender_api::caller::endpoints::ADD_MESSAGE,
axum::http::Method::POST,
true,
)
.await
{
Ok(req) => match app.clone().oneshot(req).await {
Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
}
pub async fn get_contact(
pub async fn get_message(
app: &axum::Router,
id: &uuid::Uuid,
) -> Result<axum::response::Response, axum::http::Error> {
let uri = format!(
"{}?id={}",
textsender_api::caller::endpoints::GET_CONTACT,
textsender_api::caller::endpoints::GET_MESSAGE,
id
);
match super::run_post(None, &uri, axum::http::Method::GET, false).await {
Ok(req) => match app.clone().oneshot(req).await {
Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
match super::run_post(None, &uri, axum::http::Method::GET, false).await {
Ok(req) => match app.clone().oneshot(req).await {
Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
}
}
@@ -321,7 +335,6 @@ mod request {
}
}
#[tokio::test]
async fn test_create_contact() {
let tm_pool = db_mgr::get_pool().await.unwrap();
@@ -532,7 +545,10 @@ async fn test_create_message() {
.await;
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
let message = &resp.data[0];
assert_eq!(TEST_MESSAGE_CONTENT, message.content, "The content of the created message should match");
assert_eq!(
TEST_MESSAGE_CONTENT, message.content,
"The content of the created message should match"
);
}
Err(err) => {
assert!(false, "Error: {:?}", err);
@@ -542,7 +558,62 @@ async fn test_create_message() {
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
}
/*
#[tokio::test]
async fn test_get_message()
*/
async fn test_get_message() {
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;
let mut message_result: Option<textsender_models::message::Message> = None;
// Send request
match request::message::create_message(&app).await {
Ok(response) => {
let resp = util::get_resp_data::<
textsender_api::caller::message::response::AddMessageResponse,
>(response)
.await;
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
let message = &resp.data[0];
assert_eq!(
TEST_MESSAGE_CONTENT, message.content,
"The content of the created message should match"
);
message_result = Some(message.clone());
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
};
assert_eq!(true, message_result.is_some());
let message = message_result.unwrap();
let message_id = message.id.unwrap();
match request::message::get_message(&app, &message_id).await {
Ok(response) => {
let resp = util::get_resp_data::<
textsender_api::caller::message::response::GetMessageResponse,
>(response)
.await;
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
}