From 86a66a420c4c05907e6fb613a09a3a358420c693 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sun, 19 May 2024 00:35:49 +0530 Subject: [PATCH] feat: define service group and UserServicesInterface with mocking --- src/identity/application/services/mod.rs | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/identity/application/services/mod.rs b/src/identity/application/services/mod.rs index 299104e..686c180 100644 --- a/src/identity/application/services/mod.rs +++ b/src/identity/application/services/mod.rs @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later +use derive_builder::Builder; +use mockall::predicate::*; +use mockall::*; use serde::{Deserialize, Serialize}; mod delete_user; @@ -35,3 +38,58 @@ pub enum UserCommand { SetAdmin(SetAdminCommand), ResendVerificationEmail(ResendVerificationEmailCommand), } + +#[automock] +pub trait UserServicesInterface: Send + Sync { + fn delete_user(&self) -> delete_user::DeleteUserServiceObj; + fn login(&self) -> login::LoginServiceObj; + fn mark_user_verified(&self) -> mark_user_verified::MarkUserVerifiedServiceObj; + fn register_user(&self) -> register_user::RegisterUserServiceObj; + fn resend_verification_email( + &self, + ) -> resend_verification_email::ResendVerificationEmailServiceObj; + fn set_user_admin(&self) -> set_user_admin::SetUserAdminServiceObj; + fn update_email(&self) -> update_email::UpdateEmailServiceObj; + fn update_password(&self) -> update_password::UpdatePasswordServiceObj; +} + +#[derive(Clone, Builder)] +pub struct UserServices { + delete_user: delete_user::DeleteUserServiceObj, + login: login::LoginServiceObj, + mark_user_verified: mark_user_verified::MarkUserVerifiedServiceObj, + register_user: register_user::RegisterUserServiceObj, + resend_verification_email: resend_verification_email::ResendVerificationEmailServiceObj, + set_user_admin: set_user_admin::SetUserAdminServiceObj, + update_email: update_email::UpdateEmailServiceObj, + update_password: update_password::UpdatePasswordServiceObj, +} + +impl UserServicesInterface for UserServices { + fn delete_user(&self) -> delete_user::DeleteUserServiceObj { + self.delete_user.clone() + } + fn login(&self) -> login::LoginServiceObj { + self.login.clone() + } + fn mark_user_verified(&self) -> mark_user_verified::MarkUserVerifiedServiceObj { + self.mark_user_verified.clone() + } + fn register_user(&self) -> register_user::RegisterUserServiceObj { + self.register_user.clone() + } + fn resend_verification_email( + &self, + ) -> resend_verification_email::ResendVerificationEmailServiceObj { + self.resend_verification_email.clone() + } + fn set_user_admin(&self) -> set_user_admin::SetUserAdminServiceObj { + self.set_user_admin.clone() + } + fn update_email(&self) -> update_email::UpdateEmailServiceObj { + self.update_email.clone() + } + fn update_password(&self) -> update_password::UpdatePasswordServiceObj { + self.update_password.clone() + } +}