feat: db: username_exists port

This commit is contained in:
Aravinth Manivannan 2024-05-17 23:22:15 +05:30
parent b6304193f0
commit c8edab57a8
Signed by: realaravinth
GPG key ID: F8F50389936984FF
3 changed files with 66 additions and 0 deletions

View 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,
}

View 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;

View 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)
}
}