mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-05-22 01:29:11 -05:00
WIP: Get some tests "closer" to passing.
This commit is contained in:
@@ -101,8 +101,8 @@ pub async fn register_user_handler(
|
||||
let hashed_password = hash_password(&request.password)?;
|
||||
|
||||
const INSERT_USER_QUERY: &str = formatcp!(
|
||||
" \
|
||||
INSERT INTO '{USER_TABLE}' \
|
||||
"\
|
||||
INSERT INTO \"{USER_TABLE}\" \
|
||||
(email, password_hash) \
|
||||
VALUES \
|
||||
(:email, :password_hash) \
|
||||
@@ -122,7 +122,7 @@ pub async fn register_user_handler(
|
||||
.await
|
||||
.map_err(|_err| {
|
||||
#[cfg(debug_assertions)]
|
||||
log::debug!("Failed to register new user {normalized_email}: {_err}");
|
||||
log::info!("Failed to register new user {normalized_email}: {_err:?}");
|
||||
|
||||
// The insert will fail if the user is already registered
|
||||
AuthError::Conflict
|
||||
|
||||
@@ -300,7 +300,9 @@ pub async fn get_user_by_id(
|
||||
}
|
||||
|
||||
pub async fn user_exists(state: &AppState, email: &str) -> bool {
|
||||
const QUERY: &str = formatcp!(r#"SELECT EXISTS(SELECT 1 FROM "{USER_TABLE}" WHERE email = $1)"#);
|
||||
const QUERY: &str =
|
||||
formatcp!(r#"SELECT CAST(EXISTS(SELECT 1 FROM "{USER_TABLE}" WHERE email = $1) AS INTEGER)"#);
|
||||
// formatcp!(r#"SELECT EXISTS(SELECT 1 FROM "{USER_TABLE}" WHERE email = $1)"#);
|
||||
|
||||
return match state
|
||||
.user_conn()
|
||||
|
||||
@@ -165,7 +165,13 @@ impl ConnectionManager {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(new_db);
|
||||
if !new_db {
|
||||
if cfg!(feature = "pg") {
|
||||
log::warn!("Re-using existing DB for test :/. Should only happen for shared external DBs.");
|
||||
} else {
|
||||
panic!("Expected 'fresh' DB for test");
|
||||
}
|
||||
}
|
||||
|
||||
return Self {
|
||||
state: Arc::new(ConnectionManagerState {
|
||||
@@ -371,6 +377,15 @@ async fn init_db<'a>(
|
||||
false
|
||||
};
|
||||
|
||||
// TODO: Remove sanity check.
|
||||
conn
|
||||
.read_query_rows(
|
||||
r#"SELECT EXISTS(SELECT 1 FROM "_user" WHERE email = 'foo')"#,
|
||||
(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
return Ok((conn, Default::default(), init_schema));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user