From 22b6478c07cb3241e966a9e56b78fd4ec375f3b9 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 17 Jun 2026 15:28:01 -0400 Subject: [PATCH] Test change --- tests/test.rs | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/tests/test.rs b/tests/test.rs index 437c80a..942598c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -176,22 +176,11 @@ mod request { "user_id": super::TEST_USER_ID, }); - /* - let req = axum::http::Request::builder() - .method(axum::http::Method::POST) - .uri(textsender_api::caller::endpoints::ADD_CONTACT) - .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(); - */ match run_post( - &payload, + Some(&payload), textsender_api::caller::endpoints::ADD_CONTACT, axum::http::Method::POST, + true, ) .await { @@ -206,13 +195,22 @@ mod request { pub async fn get_contact( app: &axum::Router, id: &uuid::Uuid, - ) -> Result { + ) -> Result { let uri = format!( "{}?id={}", textsender_api::caller::endpoints::GET_CONTACT, id ); + match 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), + } + + /* let req = axum::http::Request::builder() .method(axum::http::Method::GET) .uri(uri) @@ -225,6 +223,7 @@ mod request { .unwrap(); app.clone().oneshot(req).await + */ } pub async fn update_contact_names( @@ -305,12 +304,21 @@ mod request { */ pub async fn run_post( - payload: &serde_json::Value, + payload: Option<&serde_json::Value>, uri: &str, method: axum::http::Method, + has_body: bool, ) -> Result, axum::http::Error> { - // textsender_api::caller::endpoints::ADD_MESSAGE) - //axum::http::Method::POST) + let body = if has_body { + assert_eq!( + true, + payload.is_some(), + "Has request body and payload has data" + ); + axum::body::Body::from(payload.unwrap().to_string()) + } else { + axum::body::Body::empty() + }; match axum::http::Request::builder() .method(method) .uri(uri) @@ -319,7 +327,7 @@ mod request { axum::http::header::AUTHORIZATION, super::bearer_auth().await, ) - .body(axum::body::Body::from(payload.to_string())) + .body(body) { Ok(t) => Ok(t), Err(err) => Err(err),