feat: t mock update_password service and test init utils for cmd and event

This commit is contained in:
Aravinth Manivannan 2025-01-21 14:15:33 +05:30
parent 04daa0a7c3
commit 98fa1f21fc
Signed by: realaravinth
GPG key ID: F8F50389936984FF
4 changed files with 45 additions and 0 deletions

View file

@ -37,6 +37,14 @@ impl UpdatePasswordCommand {
mod tests { mod tests {
use super::*; use super::*;
impl UpdatePasswordCommand {
pub fn get_cmd() -> Self {
Self {
hashed_new_passowrd: "foo".into(),
}
}
}
#[test] #[test]
fn test_cmd() { fn test_cmd() {
let config = argon2_creds::Config::default(); let config = argon2_creds::Config::default();

View file

@ -15,3 +15,19 @@ impl PasswordUpdatedEvent {
Self { hashed_password } 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(),
}
}
}
}

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net> // SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
// //
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
use mockall::predicate::*;
use mockall::*;
pub mod command; pub mod command;
pub mod events; pub mod events;
@ -8,6 +10,7 @@ pub mod service;
use super::errors::*; use super::errors::*;
#[automock]
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait UpdatePasswordUseCase: Send + Sync { pub trait UpdatePasswordUseCase: Send + Sync {
async fn update_password( async fn update_password(

View file

@ -21,6 +21,24 @@ impl UpdatePasswordUseCase for UpdatePasswordService {
mod tests { mod tests {
use super::*; use super::*;
impl UpdatePasswordService {
pub fn mock_service(
times: Option<usize>,
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] #[actix_rt::test]
async fn test_service() { async fn test_service() {
let username = "realaravinth"; let username = "realaravinth";