1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Database testing

This commit is contained in:
Quentin Gliech
2022-08-04 15:32:10 +02:00
parent 3cfd0f1553
commit 646a0f26d6
2 changed files with 45 additions and 0 deletions

View File

@ -841,3 +841,33 @@ pub async fn add_user_email_verification_code(
Ok(verification)
}
#[cfg(test)]
mod tests {
use super::*;
#[sqlx::test(migrator = "crate::MIGRATOR")]
async fn test_user_registration_and_login(pool: sqlx::PgPool) -> anyhow::Result<()> {
let mut txn = pool.begin().await?;
let exists = username_exists(&mut txn, "john").await?;
assert!(!exists);
let hasher = Argon2::default();
let user = register_user(&mut txn, hasher, "john", "hunter2").await?;
assert_eq!(user.username, "john");
let exists = username_exists(&mut txn, "john").await?;
assert!(exists);
let session = login(&mut txn, "john", "hunter2").await?;
assert_eq!(session.user.data, user.data);
let user2 = lookup_user_by_username(&mut txn, "john").await?;
assert_eq!(user.data, user2.data);
txn.commit().await?;
Ok(())
}
}