Update name of user endpoint (#9)
Rust Build / Test Suite (push) Successful in 48s
Rust Build / Rustfmt (push) Successful in 1m23s
Rust Build / Check (push) Successful in 1m35s
Rust Build / Clippy (push) Successful in 1m13s
Rust Build / build (push) Successful in 2m57s
Rust Build / Rustfmt (pull_request) Successful in 1m15s
Rust Build / Test Suite (pull_request) Successful in 1m38s
Rust Build / Check (pull_request) Successful in 1m50s
Rust Build / Clippy (pull_request) Successful in 1m24s
Rust Build / build (pull_request) Successful in 2m59s

Reviewed-on: phoenix/textsender-auth#9
This commit was merged in pull request #9.
This commit is contained in:
2026-06-12 17:27:46 -04:00
parent e3ee24c131
commit b678c098cb
7 changed files with 285 additions and 2 deletions
+136
View File
@@ -172,6 +172,7 @@ pub mod requests {
app.clone().oneshot(req).await
}
/// Function to call update password endpoint
pub async fn update_password(
app: &axum::Router,
user_id: &uuid::Uuid,
@@ -198,6 +199,32 @@ pub mod requests {
Err(err) => Err(err),
}
}
/// Function to call update name of user endpoint
pub async fn update_name_of_user(
app: &axum::Router,
user_id: &uuid::Uuid,
firstname: &str,
lastname: &str,
) -> Result<axum::response::Response, axum::http::Error> {
let payload = serde_json::json!({
"user_id": user_id,
"firstname": firstname,
"lastname": lastname,
});
match axum::http::Request::builder()
.method(axum::http::Method::PATCH)
.uri(super::callers::endpoints::UPDATE_USER_NAME)
.header(axum::http::header::CONTENT_TYPE, "application/json")
.body(axum::body::Body::from(payload.to_string()))
{
Ok(req) => match app.clone().oneshot(req).await {
Ok(resp) => Ok(resp),
Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
}
}
/// Test user firstname
@@ -213,6 +240,11 @@ const TEST_PHONE_NUMBER: &str = "+10123456789";
/// Test updated user password
const TEST_UPDATED_PASSWORD: &str = "3cnf29ry8q27i3yrc928qi37ryndxc2198q7yd9xzq12837e";
/// Test updated user firstname
const TEST_UPDATED_FIRSTNAME: &str = "Kuoth";
/// Test updated user lastname
const TEST_UPDATED_LASTNAME: &str = "Wech";
/// Test service username
const TEST_SERVICE_USERNAME: &str = "swoon";
/// Test service passphrase
@@ -453,6 +485,41 @@ mod flow {
Err(err) => Err(std::io::Error::other(err.to_string())),
}
}
pub async fn update_name_of_user(
app: &axum::Router,
user_id: &uuid::Uuid,
firstname: &str,
lastname: &str,
) -> Result<textsender_models::user::User, std::io::Error> {
match requests::update_name_of_user(app, user_id, firstname, lastname).await {
Ok(response) => {
if axum::http::StatusCode::OK != response.status() {
Err(std::io::Error::other(format!(
"Status code is off {:?}",
response.status()
)))
} else {
match util::convert_response::<callers::login::response::UserUpdateNameResponse>(
response,
)
.await
{
Ok(response) => {
if response.data.len() > 0 {
let user = response.data[0].clone();
Ok(user)
} else {
Err(std::io::Error::other("No data returned"))
}
}
Err(err) => Err(err),
}
}
}
Err(err) => Err(std::io::Error::other(err.to_string())),
}
}
}
#[tokio::test]
@@ -853,3 +920,72 @@ async fn test_update_password() {
}
}
}
#[tokio::test]
async fn test_update_name_of_password() {
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(e) => {
assert!(false, "Error: {:?}", e.to_string());
}
}
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
db::init::migrations(&pool).await;
let app = init::routes().await.layer(axum::Extension(pool));
match flow::register_user(&app).await {
Ok(user) => match flow::login_user(&app, &user.username, TEST_PASSWORD).await {
Ok(login_result) => {
assert_eq!(
false,
login_result.access_token.is_empty(),
"Access token is empty when it should not be"
);
match flow::update_name_of_user(
&app,
&user.id,
TEST_UPDATED_FIRSTNAME,
TEST_UPDATED_LASTNAME,
)
.await
{
Ok(user) => {
assert_eq!(
TEST_UPDATED_FIRSTNAME, user.firstname,
"Firstname do not match"
);
assert_eq!(
TEST_UPDATED_LASTNAME, user.lastname,
"Lastname do not match"
);
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
},
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
match db_mgr::drop_database(&tm_pool, &db_name).await {
Ok(()) => {}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}