database: add tests for `find_user_by_id`

This commit is contained in:
MedzikUser 2022-04-23 23:52:54 +02:00
parent 2924e38592
commit 6ae8d6fa9f
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
1 changed files with 33 additions and 0 deletions

View File

@ -67,6 +67,7 @@ impl Database {
})
}
/// Find user by UUID
pub async fn find_user_by_id(&self, id: String) -> Result<User, Error> {
let query = sqlx::query_as::<_, User>("SELECT * FROM user WHERE id = ?").bind(id);
@ -171,4 +172,36 @@ mod tests {
assert_eq!(err.to_string(), "user not found")
}
#[tokio::test]
async fn find_user_by_id() {
let db = open_db().await;
new_user(&db).await;
let user = User::new("medzik", "Qwerty1234!");
let res = db
.find_user_by_id(user.id)
.await
.expect("find user");
assert_eq!(res.password, user.password)
}
#[tokio::test]
async fn find_user_wrong_id() {
let db = open_db().await;
new_user(&db).await;
let other_user = User::new("other_user", "secretpassphrase123!");
let err = db
.find_user_by_id(other_user.id)
.await
.unwrap_err();
assert_eq!(err.to_string(), "user not found")
}
}