feat: db: port for deleting verification secret

This commit is contained in:
Aravinth Manivannan 2024-05-18 18:27:07 +05:30
parent 6858633cb9
commit 1da8f791b4
Signed by: realaravinth
GPG key ID: F8F50389936984FF

View file

@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// 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<super::verification_secret_exists::VerifySecretExistsMsg> 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<dyn DeleteVerificationSecretOutDBPort>;
#[cfg(test)]
pub mod tests {
use super::*;
use std::sync::Arc;
pub fn mock_delete_verification_secret_db_port(
times: Option<usize>,
) -> 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)
}
}