diff --git a/src/identity/application/services/update_password/command.rs b/src/identity/application/services/update_password/command.rs index 5212806..012f9a2 100644 --- a/src/identity/application/services/update_password/command.rs +++ b/src/identity/application/services/update_password/command.rs @@ -37,6 +37,14 @@ impl UpdatePasswordCommand { mod tests { use super::*; + impl UpdatePasswordCommand { + pub fn get_cmd() -> Self { + Self { + hashed_new_passowrd: "foo".into(), + } + } + } + #[test] fn test_cmd() { let config = argon2_creds::Config::default(); diff --git a/src/identity/application/services/update_password/events.rs b/src/identity/application/services/update_password/events.rs index dc0662d..13aa3de 100644 --- a/src/identity/application/services/update_password/events.rs +++ b/src/identity/application/services/update_password/events.rs @@ -15,3 +15,19 @@ impl PasswordUpdatedEvent { Self { hashed_password } } } + +// events +#[cfg(test)] +mod tests { + use super::*; + + use crate::identity::application::services::update_password::command::UpdatePasswordCommand; + + impl PasswordUpdatedEvent { + pub fn get_event(cmd: &UpdatePasswordCommand) -> Self { + Self { + hashed_password: cmd.hashed_new_passowrd().clone(), + } + } + } +} diff --git a/src/identity/application/services/update_password/mod.rs b/src/identity/application/services/update_password/mod.rs index 19caa82..5c009fd 100644 --- a/src/identity/application/services/update_password/mod.rs +++ b/src/identity/application/services/update_password/mod.rs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2024 Aravinth Manivannan // // SPDX-License-Identifier: AGPL-3.0-or-later +use mockall::predicate::*; +use mockall::*; pub mod command; pub mod events; @@ -8,6 +10,7 @@ pub mod service; use super::errors::*; +#[automock] #[async_trait::async_trait] pub trait UpdatePasswordUseCase: Send + Sync { async fn update_password( diff --git a/src/identity/application/services/update_password/service.rs b/src/identity/application/services/update_password/service.rs index feee380..f9653e5 100644 --- a/src/identity/application/services/update_password/service.rs +++ b/src/identity/application/services/update_password/service.rs @@ -21,6 +21,24 @@ impl UpdatePasswordUseCase for UpdatePasswordService { mod tests { use super::*; + impl UpdatePasswordService { + pub fn mock_service( + times: Option, + cmd: command::UpdatePasswordCommand, + ) -> UpdatePasswordServiceObj { + let mut m = MockUpdatePasswordUseCase::default(); + let res = events::PasswordUpdatedEvent::get_event(&cmd); + + if let Some(times) = times { + m.expect_update_password().times(times).return_const(res); + } else { + m.expect_update_password().return_const(res); + } + + std::sync::Arc::new(m) + } + } + #[actix_rt::test] async fn test_service() { let username = "realaravinth";