Fix server tests

This commit is contained in:
Adrian Wozniak 2020-05-23 19:13:42 +02:00
parent 39760b5956
commit 7a17053909

View File

@ -9,6 +9,7 @@ use crate::db::projects::CreateProject;
use crate::db::{DbExecutor, DbPooledConn}; use crate::db::{DbExecutor, DbPooledConn};
use crate::errors::ServiceErrors; use crate::errors::ServiceErrors;
use crate::schema::users::all_columns; use crate::schema::users::all_columns;
use diesel::connection::TransactionManager;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct FindUser { pub struct FindUser {
@ -130,6 +131,10 @@ impl Handler<Register> for DbExecutor {
.get() .get()
.map_err(|_| ServiceErrors::DatabaseConnectionLost)?; .map_err(|_| ServiceErrors::DatabaseConnectionLost)?;
let tm = conn.transaction_manager();
tm.begin_transaction(conn)
.map_err(|_| ServiceErrors::DatabaseConnectionLost)?;
let matching = count_matching_users(msg.name.as_str(), msg.email.as_str(), conn); let matching = count_matching_users(msg.name.as_str(), msg.email.as_str(), conn);
if matching > 0 { if matching > 0 {
@ -178,6 +183,8 @@ impl Handler<Register> for DbExecutor {
.execute(conn) .execute(conn)
.map_err(|_| ServiceErrors::RegisterCollision)?; .map_err(|_| ServiceErrors::RegisterCollision)?;
} }
tm.commit_transaction(conn)
.map_err(|_| ServiceErrors::DatabaseConnectionLost)?;
Ok(()) Ok(())
} }