Code changes
This commit is contained in:
+81
-72
@@ -129,8 +129,22 @@ pub fn token_fields() -> (String, String, String) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test User Id
|
||||||
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
||||||
|
|
||||||
|
/// Test contact phone number
|
||||||
|
pub const TEST_CONTACT_PHONE_NUMBER: &str = "+10123456789";
|
||||||
|
|
||||||
|
/// Test contact updated firstname
|
||||||
|
pub const TEST_CONTACT_UPDATED_FIRSTNAME: &str = "Johnny";
|
||||||
|
/// Test contact updated lastname
|
||||||
|
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";
|
||||||
|
|
||||||
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
||||||
let key: String = textsender_models::envy::environment::get_secret_main_key()
|
let key: String = textsender_models::envy::environment::get_secret_main_key()
|
||||||
.await
|
.await
|
||||||
@@ -209,21 +223,6 @@ mod request {
|
|||||||
},
|
},
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
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 update_contact_names(
|
pub async fn update_contact_names(
|
||||||
@@ -232,7 +231,7 @@ mod request {
|
|||||||
firstname: Option<&str>,
|
firstname: Option<&str>,
|
||||||
lastname: Option<&str>,
|
lastname: Option<&str>,
|
||||||
nickname: Option<&str>,
|
nickname: Option<&str>,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = serde_json::json!({
|
let payload = serde_json::json!({
|
||||||
"firstname": firstname,
|
"firstname": firstname,
|
||||||
"lastname": lastname,
|
"lastname": lastname,
|
||||||
@@ -241,67 +240,54 @@ mod request {
|
|||||||
"id": id
|
"id": id
|
||||||
});
|
});
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(Some(&payload), textsender_api::caller::endpoints::UPDATE_CONTACT_NAME, axum::http::Method::PATCH, true).await {
|
||||||
.method(axum::http::Method::PATCH)
|
Ok(req) => match app.clone().oneshot(req).await {
|
||||||
.uri(textsender_api::caller::endpoints::UPDATE_CONTACT_NAME)
|
Ok(response) => Ok(response),
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.header(
|
},
|
||||||
axum::http::header::AUTHORIZATION,
|
Err(err) => Err(err),
|
||||||
super::bearer_auth().await,
|
}
|
||||||
)
|
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
|
||||||
.unwrap();
|
|
||||||
app.clone().oneshot(req).await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
pub mod message {
|
pub mod message {
|
||||||
|
use tower::ServiceExt;
|
||||||
|
|
||||||
pub async fn create_message(
|
pub async fn create_message(
|
||||||
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!({
|
||||||
"content": super::TEST_MESSAGE_CONTENT,
|
"content": super::super::TEST_MESSAGE_CONTENT,
|
||||||
"user_id": super::TEST_USER_ID,
|
"user_id": super::super::TEST_USER_ID,
|
||||||
});
|
});
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match super::run_post(Some(&payload), textsender_api::caller::endpoints::ADD_MESSAGE, axum::http::Method::POST, true).await {
|
||||||
.method(axum::http::Method::POST)
|
Ok(req) => match app.clone().oneshot(req).await {
|
||||||
.uri(textsender_api::caller::endpoints::ADD_MESSAGE)
|
Ok(response) => Ok(response),
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.header(
|
},
|
||||||
axum::http::header::AUTHORIZATION,
|
Err(err) => Err(err),
|
||||||
super::bearer_auth().await,
|
}
|
||||||
)
|
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
|
||||||
.unwrap();
|
|
||||||
app.clone().oneshot(req).await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_contact(
|
pub async fn get_contact(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let uri = format!(
|
let uri = format!(
|
||||||
"{}?id={}",
|
"{}?id={}",
|
||||||
textsender_api::caller::endpoints::GET_CONTACT,
|
textsender_api::caller::endpoints::GET_CONTACT,
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match super::run_post(None, &uri, axum::http::Method::GET, false).await {
|
||||||
.method(axum::http::Method::GET)
|
Ok(req) => match app.clone().oneshot(req).await {
|
||||||
.uri(uri)
|
Ok(response) => Ok(response),
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.header(
|
},
|
||||||
axum::http::header::AUTHORIZATION,
|
Err(err) => Err(err),
|
||||||
super::bearer_auth().await,
|
}
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
pub async fn run_post(
|
pub async fn run_post(
|
||||||
payload: Option<&serde_json::Value>,
|
payload: Option<&serde_json::Value>,
|
||||||
@@ -335,18 +321,6 @@ mod request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test contact phone number
|
|
||||||
pub const TEST_CONTACT_PHONE_NUMBER: &str = "+10123456789";
|
|
||||||
|
|
||||||
/// Test contact updated firstname
|
|
||||||
pub const TEST_CONTACT_UPDATED_FIRSTNAME: &str = "Johnny";
|
|
||||||
/// Test contact updated lastname
|
|
||||||
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]
|
#[tokio::test]
|
||||||
async fn test_create_contact() {
|
async fn test_create_contact() {
|
||||||
@@ -530,10 +504,45 @@ 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_create_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;
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_
|
async fn test_get_message()
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_
|
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user