feat: t mock update_password service and test init utils for cmd and event
This commit is contained in:
parent
04daa0a7c3
commit
98fa1f21fc
4 changed files with 45 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// 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(
|
||||
|
|
|
@ -21,6 +21,24 @@ impl UpdatePasswordUseCase for UpdatePasswordService {
|
|||
mod tests {
|
||||
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]
|
||||
async fn test_service() {
|
||||
let username = "realaravinth";
|
||||
|
|
Loading…
Add table
Reference in a new issue