feat: define interface for checking if user email exists

This commit is contained in:
realaravinth 2022-05-11 13:31:14 +05:30
parent 136439c97a
commit 9595ea232b
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
2 changed files with 12 additions and 0 deletions

View file

@ -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<bool>;
/// check if email exists
async fn email_exists(&self, email: &str) -> DBResult<bool>;
}
/// Trait to clone MCDatabase

View file

@ -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"
);
}