From 1da8f791b459e23e09a08c67574c5381c5812333 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sat, 18 May 2024 18:27:07 +0530 Subject: [PATCH] feat: db: port for deleting verification secret --- .../output/db/delete_verification_secret.rs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/identity/application/port/output/db/delete_verification_secret.rs diff --git a/src/identity/application/port/output/db/delete_verification_secret.rs b/src/identity/application/port/output/db/delete_verification_secret.rs new file mode 100644 index 0000000..4318fbb --- /dev/null +++ b/src/identity/application/port/output/db/delete_verification_secret.rs @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use derive_builder::Builder; +use mockall::predicate::*; +use mockall::*; +use serde::{Deserialize, Serialize}; + +pub use super::create_verification_secret::REGISTRATION_SECRET_PURPOSE; +use super::errors::*; +#[cfg(test)] +#[allow(unused_imports)] +pub use tests::*; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Builder)] +pub struct DeleteSecretMsg { + pub secret: String, + pub username: String, +} + +impl From for DeleteSecretMsg { + fn from(value: super::verification_secret_exists::VerifySecretExistsMsg) -> Self { + Self { + secret: value.secret, + username: value.username, + } + } +} + +#[automock] +#[async_trait::async_trait] +pub trait DeleteVerificationSecretOutDBPort: Send + Sync { + async fn delete_verification_secret(&self, msg: &DeleteSecretMsg) -> OutDBPortResult<()>; +} + +pub type DeleteVerificationSecretOutDBPortObj = + std::sync::Arc; + +#[cfg(test)] +pub mod tests { + use super::*; + + use std::sync::Arc; + + pub fn mock_delete_verification_secret_db_port( + times: Option, + ) -> DeleteVerificationSecretOutDBPortObj { + let mut m = MockDeleteVerificationSecretOutDBPort::new(); + if let Some(times) = times { + m.expect_delete_verification_secret() + .times(times) + .returning(|_| Ok(())); + } else { + m.expect_delete_verification_secret().returning(|_| Ok(())); + } + + Arc::new(m) + } +}