diff --git a/src/identity/application/port/output/db/errors.rs b/src/identity/application/port/output/db/errors.rs new file mode 100644 index 0000000..09a9874 --- /dev/null +++ b/src/identity/application/port/output/db/errors.rs @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use derive_more::Display; +use serde::{Deserialize, Serialize}; + +pub type OutDBPortResult = Result; + +#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +pub enum OutDBPortError { + InternalError, + VerificationOTPSecretExists, +} diff --git a/src/identity/application/port/output/db/mod.rs b/src/identity/application/port/output/db/mod.rs new file mode 100644 index 0000000..b3e3eeb --- /dev/null +++ b/src/identity/application/port/output/db/mod.rs @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +pub mod create_verification_secret; +pub mod email_exists; +pub mod errors; +pub mod username_exists; +//pub mod get_verification_secret; +//pub mod delete_verification_secret; diff --git a/src/identity/application/port/output/db/username_exists.rs b/src/identity/application/port/output/db/username_exists.rs new file mode 100644 index 0000000..2bcacbc --- /dev/null +++ b/src/identity/application/port/output/db/username_exists.rs @@ -0,0 +1,42 @@ +// 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 UsernameExistsOutDBPort: Send + Sync { + async fn username_exists(&self, username: &str) -> OutDBPortResult; +} + +pub type UsernameExistsOutDBPortObj = std::sync::Arc; + +#[cfg(test)] +pub mod tests { + use super::*; + + use std::sync::Arc; + + pub fn mock_username_exists_db_port( + times: Option, + returning: bool, + ) -> UsernameExistsOutDBPortObj { + let mut m = MockUsernameExistsOutDBPort::new(); + if let Some(times) = times { + m.expect_username_exists() + .times(times) + .returning(move |_| Ok(returning)); + } else { + m.expect_username_exists().returning(move |_| Ok(returning)); + } + + Arc::new(m) + } +}