From 52458d7f0d23972408391fcb2eda5fa301a1a55f Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Thu, 3 Oct 2024 18:45:46 +0300 Subject: [PATCH 1/2] feat(#172): RqLogin --- server/src/handlers/register_user.rs | 56 ++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/server/src/handlers/register_user.rs b/server/src/handlers/register_user.rs index 3ac4b12e..279d3c98 100644 --- a/server/src/handlers/register_user.rs +++ b/server/src/handlers/register_user.rs @@ -25,6 +25,14 @@ use axum::extract::State; use axum::http::StatusCode; use axum::Json; use log::info; +use serde::Deserialize; + +/// Rq Login. +#[derive(Deserialize)] +pub struct RqLogin { + /// Login. + login: String, +} /// Register user. /// @@ -33,9 +41,9 @@ use log::info; /// * `payload`: JSON payload pub async fn register_user( State(config): State, - Json(payload): Json, + Json(payload): Json, ) -> Result { - let mut newcomer = User::new(payload.login.clone()); + let mut newcomer = User::new(payload.login); let fakehub = &config.fakehub; let github = fakehub.main(); let mut github = github @@ -56,9 +64,8 @@ pub async fn register_user( #[cfg(test)] mod tests { - use crate::handlers::register_user::register_user; + use crate::handlers::register_user::{register_user, RqLogin}; use crate::objects::fakehub::FakeHub; - use crate::objects::user::User; use crate::ServerConfig; use anyhow::Result; use axum::extract::State; @@ -73,10 +80,14 @@ mod tests { }; let state = State(server.clone()); let registration = "new1234"; - let status = - register_user(state, Json::from(User::new(String::from(registration)))) - .await - .expect("Failed to register user"); + let status = register_user( + state, + Json::from(RqLogin { + login: String::from(registration), + }), + ) + .await + .expect("Failed to register user"); let fakehub = server.fakehub; let github = fakehub.main(); let locked = github.lock().expect("Failed to lock GitHub"); @@ -95,9 +106,14 @@ mod tests { }; let state = State(server.clone()); let registration = "new1234"; - register_user(state, Json::from(User::new(String::from(registration)))) - .await - .expect("Failed to register user"); + register_user( + state, + Json::from(RqLogin { + login: String::from(registration), + }), + ) + .await + .expect("Failed to register user"); let fakehub = server.fakehub; let github = fakehub.main(); let locked = github.lock().expect("Failed to lock GitHub"); @@ -122,9 +138,14 @@ mod tests { fakehub: FakeHub::default(), }; let state = State(server); - register_user(state, Json::from(User::new(String::from("jeff")))) - .await - .expect("Failed to register user"); + register_user( + state, + Json::from(RqLogin { + login: String::from("jeff"), + }), + ) + .await + .expect("Failed to register user"); } #[tokio::test] @@ -133,7 +154,12 @@ mod tests { fakehub: FakeHub::default(), }; let state = State(server); - let result = register_user(state, Json(User::new(String::from("jeff")))).await; + let result = register_user( + state, + Json::from(RqLogin { + login: String::from("jeff"), + }), + ).await; match result { Err((status, _)) => { assert_that!(status, is(equal_to(StatusCode::CONFLICT))); From de9647e71cf2639ad946a0c112effc3d4a312045 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Thu, 3 Oct 2024 18:58:43 +0300 Subject: [PATCH 2/2] feat(#172): clean for check --- server/src/handlers/register_user.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/handlers/register_user.rs b/server/src/handlers/register_user.rs index 279d3c98..94167bda 100644 --- a/server/src/handlers/register_user.rs +++ b/server/src/handlers/register_user.rs @@ -159,7 +159,8 @@ mod tests { Json::from(RqLogin { login: String::from("jeff"), }), - ).await; + ) + .await; match result { Err((status, _)) => { assert_that!(status, is(equal_to(StatusCode::CONFLICT)));