From 6e45c643b1ead163a569d5b9d3f259f09c3365eb Mon Sep 17 00:00:00 2001 From: realaravinth Date: Thu, 26 May 2022 20:35:25 +0530 Subject: [PATCH] feat: def get_email trait --- db/db-core/src/errors.rs | 1 + db/db-core/src/lib.rs | 3 +++ db/db-core/src/tests.rs | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/db/db-core/src/errors.rs b/db/db-core/src/errors.rs index 3c0c8289..f3c93dcc 100644 --- a/db/db-core/src/errors.rs +++ b/db/db-core/src/errors.rs @@ -41,6 +41,7 @@ pub enum DBError { /// Account not found #[error("Account not found")] AccountNotFound, + /// Captcha not found #[error("Captcha not found")] CaptchaNotFound, diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index 9ec6b2e9..1ebffd3f 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -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; + /// get user email + async fn get_email(&self, username: &str) -> DBResult>; + /// check if email exists async fn email_exists(&self, email: &str) -> DBResult; diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index 34cfb576..47986c1a 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -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,