Test changes
This commit is contained in:
+98
-2
@@ -170,12 +170,13 @@ mod request {
|
|||||||
|
|
||||||
pub async fn create_contact(
|
pub async fn create_contact(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = serde_json::json!({
|
let payload = serde_json::json!({
|
||||||
"phone_number": super::TEST_CONTACT_PHONE_NUMBER,
|
"phone_number": super::TEST_CONTACT_PHONE_NUMBER,
|
||||||
"user_id": super::TEST_USER_ID,
|
"user_id": super::TEST_USER_ID,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
let req = axum::http::Request::builder()
|
let req = axum::http::Request::builder()
|
||||||
.method(axum::http::Method::POST)
|
.method(axum::http::Method::POST)
|
||||||
.uri(textsender_api::caller::endpoints::ADD_CONTACT)
|
.uri(textsender_api::caller::endpoints::ADD_CONTACT)
|
||||||
@@ -186,7 +187,20 @@ mod request {
|
|||||||
)
|
)
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
.body(axum::body::Body::from(payload.to_string()))
|
||||||
.unwrap();
|
.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(
|
pub async fn get_contact(
|
||||||
@@ -240,6 +254,77 @@ mod request {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
app.clone().oneshot(req).await
|
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
|
/// Test contact phone number
|
||||||
@@ -252,6 +337,9 @@ pub const TEST_CONTACT_UPDATED_LASTNAME: &str = "CASH";
|
|||||||
/// Test contact updated nickname
|
/// Test contact updated nickname
|
||||||
pub const TEST_CONTACT_UPDATED_NICKNAME: &str = "The Man in Black";
|
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]
|
#[tokio::test]
|
||||||
async fn test_create_contact() {
|
async fn test_create_contact() {
|
||||||
let tm_pool = db_mgr::get_pool().await.unwrap();
|
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;
|
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user