Get message endpoint #14

Merged
phoenix merged 13 commits from get_message into alot_of_changes 2026-06-17 15:54:27 -04:00
Showing only changes of commit ebabd77369 - Show all commits
+98 -2
View File
@@ -170,12 +170,13 @@ mod request {
pub async fn create_contact(
app: &axum::Router,
) -> Result<axum::response::Response, std::convert::Infallible> {
) -> Result<axum::response::Response, axum::http::Error> {
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<axum::response::Response, std::convert::Infallible> {
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<axum::response::Response, std::convert::Infallible> {
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::Request<axum::body::Body>, 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_
*/