WIP: Get some tests "closer" to passing.

This commit is contained in:
Sebastian Jeltsch
2026-05-07 11:24:27 +02:00
parent 9d2306a190
commit 4055e5187e
3 changed files with 22 additions and 5 deletions
+3 -3
View File
@@ -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
+3 -1
View File
@@ -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()
+16 -1
View File
@@ -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));
}