feat: def get_email trait

This commit is contained in:
realaravinth 2022-05-26 20:35:25 +05:30
parent aad49dbb94
commit 6e45c643b1
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
3 changed files with 18 additions and 0 deletions

View file

@ -41,6 +41,7 @@ pub enum DBError {
/// Account not found
#[error("Account not found")]
AccountNotFound,
/// Captcha not found
#[error("Captcha not found")]
CaptchaNotFound,

View file

@ -113,6 +113,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
/// check if username exists
async fn username_exists(&self, username: &str) -> DBResult<bool>;
/// get user email
async fn get_email(&self, username: &str) -> DBResult<Option<String>>;
/// check if email exists
async fn email_exists(&self, email: &str) -> DBResult<bool>;

View file

@ -65,6 +65,17 @@ pub async fn database_works<'a, T: MCDatabase>(
assert_eq!(name_hash.hash, p.hash, "user password matches");
assert_eq!(name_hash.username, p.username, "username matches");
// testing get_email
assert_eq!(
db.get_email(p.username)
.await
.unwrap()
.as_ref()
.unwrap()
.as_str(),
p.email.unwrap()
);
// testing email exists
assert!(
db.email_exists(p.email.as_ref().unwrap()).await.unwrap(),
@ -119,6 +130,9 @@ pub async fn database_works<'a, T: MCDatabase>(
"user registration with email is deleted; so email shouldn't exsit"
);
// testing get_email = None
assert_eq!(db.get_email(p.username).await.unwrap(), None);
// testing update email
let update_email = UpdateEmail {
username: p.username,