feat: db: email_exists port

This commit is contained in:
Aravinth Manivannan 2024-05-17 23:22:31 +05:30
parent c8edab57a8
commit d1d87fa28c
Signed by: realaravinth
GPG key ID: F8F50389936984FF

View file

@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use mockall::predicate::*;
use mockall::*;
use super::errors::*;
#[cfg(test)]
#[allow(unused_imports)]
pub use tests::*;
#[automock]
#[async_trait::async_trait]
pub trait EmailExistsOutDBPort: Send + Sync {
async fn email_exists(&self, email: &str) -> OutDBPortResult<bool>;
}
pub type EmailExistsOutDBPortObj = std::sync::Arc<dyn EmailExistsOutDBPort>;
#[cfg(test)]
pub mod tests {
use super::*;
use std::sync::Arc;
pub fn mock_email_exists_db_port(
times: Option<usize>,
returning: bool,
) -> EmailExistsOutDBPortObj {
let mut m = MockEmailExistsOutDBPort::new();
if let Some(times) = times {
m.expect_email_exists()
.times(times)
.returning(move |_| Ok(returning));
} else {
m.expect_email_exists().returning(move |_| Ok(returning));
}
Arc::new(m)
}
}