diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index e299b743..f8304999 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -86,6 +86,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase { /// check if username exists async fn username_exists(&self, username: &str) -> DBResult; + + /// check if email exists + async fn email_exists(&self, email: &str) -> DBResult; } /// Trait to clone MCDatabase diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index e6c3eda3..cdc9f04d 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -28,6 +28,10 @@ pub async fn database_works<'a, T: MCDatabase>(db: &T, p: &Register<'a>) { ); } db.register(p).await.unwrap(); + assert!( + db.email_exists(p.email.as_ref().unwrap()).await.unwrap(), + "user is registered so email should exsit" + ); assert!( db.username_exists(p.username).await.unwrap(), "user is registered so username should exsit" @@ -46,4 +50,9 @@ pub async fn database_works<'a, T: MCDatabase>(db: &T, p: &Register<'a>) { db.username_exists(p2.username).await.unwrap(), "user is registered so username should exsit" ); + assert!( + !db.email_exists(p.email.as_ref().unwrap()).await.unwrap(), + "user registration with email is deleted; so email shouldn't exsit" + ); + }