feat: db: username_exists port
This commit is contained in:
parent
b6304193f0
commit
c8edab57a8
3 changed files with 66 additions and 0 deletions
14
src/identity/application/port/output/db/errors.rs
Normal file
14
src/identity/application/port/output/db/errors.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use derive_more::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub type OutDBPortResult<V> = Result<V, OutDBPortError>;
|
||||
|
||||
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum OutDBPortError {
|
||||
InternalError,
|
||||
VerificationOTPSecretExists,
|
||||
}
|
10
src/identity/application/port/output/db/mod.rs
Normal file
10
src/identity/application/port/output/db/mod.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// 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;
|
42
src/identity/application/port/output/db/username_exists.rs
Normal file
42
src/identity/application/port/output/db/username_exists.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
// 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 UsernameExistsOutDBPort: Send + Sync {
|
||||
async fn username_exists(&self, username: &str) -> OutDBPortResult<bool>;
|
||||
}
|
||||
|
||||
pub type UsernameExistsOutDBPortObj = std::sync::Arc<dyn UsernameExistsOutDBPort>;
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn mock_username_exists_db_port(
|
||||
times: Option<usize>,
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue