Skip to content

Commit

Permalink
Merge pull request #186 from h1alexbel/173
Browse files Browse the repository at this point in the history
fix(#172): RqLogin
  • Loading branch information
h1alexbel authored Oct 3, 2024
2 parents 3aeb8b9 + de9647e commit 5eda57e
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions server/src/handlers/register_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -33,9 +41,9 @@ use log::info;
/// * `payload`: JSON payload
pub async fn register_user(
State(config): State<ServerConfig>,
Json(payload): Json<User>,
Json(payload): Json<RqLogin>,
) -> Result<StatusCode, (StatusCode, String)> {
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
Expand All @@ -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;
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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]
Expand All @@ -133,7 +154,13 @@ 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)));
Expand Down

0 comments on commit 5eda57e

Please sign in to comment.