From ebabd77369df129fde24926fe8dc1ffd5e549b33 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 17 Jun 2026 15:11:17 -0400 Subject: [PATCH] Test changes --- tests/test.rs | 100 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/tests/test.rs b/tests/test.rs index 801fc62..437c80a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -170,12 +170,13 @@ mod request { pub async fn create_contact( app: &axum::Router, - ) -> Result { + ) -> Result { let payload = serde_json::json!({ "phone_number": super::TEST_CONTACT_PHONE_NUMBER, "user_id": super::TEST_USER_ID, }); + /* let req = axum::http::Request::builder() .method(axum::http::Method::POST) .uri(textsender_api::caller::endpoints::ADD_CONTACT) @@ -186,7 +187,20 @@ mod request { ) .body(axum::body::Body::from(payload.to_string())) .unwrap(); - app.clone().oneshot(req).await + */ + match run_post( + &payload, + textsender_api::caller::endpoints::ADD_CONTACT, + axum::http::Method::POST, + ) + .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( @@ -240,6 +254,77 @@ mod request { .unwrap(); app.clone().oneshot(req).await } + + /* + pub mod message { + pub async fn create_message( + app: &axum::Router, + ) -> Result { + let payload = serde_json::json!({ + "content": super::TEST_MESSAGE_CONTENT, + "user_id": super::TEST_USER_ID, + }); + + let req = axum::http::Request::builder() + .method(axum::http::Method::POST) + .uri(textsender_api::caller::endpoints::ADD_MESSAGE) + .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 + } + + pub async fn get_contact( + app: &axum::Router, + id: &uuid::Uuid, + ) -> Result { + let uri = format!( + "{}?id={}", + textsender_api::caller::endpoints::GET_CONTACT, + id + ); + + let req = axum::http::Request::builder() + .method(axum::http::Method::GET) + .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(); + + app.clone().oneshot(req).await + } + } + */ + + pub async fn run_post( + payload: &serde_json::Value, + uri: &str, + method: axum::http::Method, + ) -> Result, axum::http::Error> { + // textsender_api::caller::endpoints::ADD_MESSAGE) + //axum::http::Method::POST) + match axum::http::Request::builder() + .method(method) + .uri(uri) + .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())) + { + Ok(t) => Ok(t), + Err(err) => Err(err), + } + } } /// Test contact phone number @@ -252,6 +337,9 @@ pub const TEST_CONTACT_UPDATED_LASTNAME: &str = "CASH"; /// Test contact updated nickname pub const TEST_CONTACT_UPDATED_NICKNAME: &str = "The Man in Black"; +/// Test message content +pub const TEST_MESSAGE_CONTENT: &str = "The wind cries mary"; + #[tokio::test] async fn test_create_contact() { let tm_pool = db_mgr::get_pool().await.unwrap(); @@ -433,3 +521,11 @@ async fn test_update_contact_names() { let _ = db_mgr::drop_database(&tm_pool, &db_name).await; } + +/* +#[tokio::test] +async fn test_ + +#[tokio::test] +async fn test_ +*/