From d1d87fa28c8ae2c31be065886169e4d07823098e Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 17 May 2024 23:22:31 +0530 Subject: [PATCH] feat: db: email_exists port --- .../port/output/db/email_exists.rs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/identity/application/port/output/db/email_exists.rs diff --git a/src/identity/application/port/output/db/email_exists.rs b/src/identity/application/port/output/db/email_exists.rs new file mode 100644 index 0000000..7a28fee --- /dev/null +++ b/src/identity/application/port/output/db/email_exists.rs @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// 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; +} + +pub type EmailExistsOutDBPortObj = std::sync::Arc; + +#[cfg(test)] +pub mod tests { + use super::*; + + use std::sync::Arc; + + pub fn mock_email_exists_db_port( + times: Option, + 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) + } +}