feat: mock mark_user_verified service and test init utils for cmd and event
This commit is contained in:
parent
6176daa83d
commit
144e30f2bf
3 changed files with 32 additions and 3 deletions
|
@ -33,4 +33,12 @@ mod tests {
|
||||||
assert_eq!(cmd.user_id(), &user_id);
|
assert_eq!(cmd.user_id(), &user_id);
|
||||||
assert_eq!(cmd.secret(), secret);
|
assert_eq!(cmd.secret(), secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MarkUserVerifiedCommand {
|
||||||
|
pub fn get_cmd() -> Self {
|
||||||
|
let user_id = UUID;
|
||||||
|
let secret = "asdfasdf";
|
||||||
|
MarkUserVerifiedCommand::new(user_id, secret.into()).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
// 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 service;
|
pub mod service;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
|
|
||||||
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait MarkUserVerifiedUseCase: Send + Sync {
|
pub trait MarkUserVerifiedUseCase: Send + Sync {
|
||||||
async fn mark_user_verified(&self, cmd: command::MarkUserVerifiedCommand)
|
async fn mark_user_verified(&self, cmd: command::MarkUserVerifiedCommand)
|
||||||
|
|
|
@ -52,9 +52,7 @@ mod tests {
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_service() {
|
async fn test_service() {
|
||||||
let user_id = UUID;
|
let cmd = command::MarkUserVerifiedCommand::get_cmd();
|
||||||
let secret = "password";
|
|
||||||
let cmd = command::MarkUserVerifiedCommand::new(user_id, secret.into()).unwrap();
|
|
||||||
|
|
||||||
// happy case
|
// happy case
|
||||||
{
|
{
|
||||||
|
@ -91,4 +89,24 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MarkUserVerifiedService {
|
||||||
|
pub fn mock_service(
|
||||||
|
times: Option<usize>,
|
||||||
|
cmd: command::MarkUserVerifiedCommand,
|
||||||
|
) -> MarkUserVerifiedServiceObj {
|
||||||
|
let mut m = MockMarkUserVerifiedUseCase::default();
|
||||||
|
let res = ();
|
||||||
|
|
||||||
|
if let Some(times) = times {
|
||||||
|
m.expect_mark_user_verified()
|
||||||
|
.times(times)
|
||||||
|
.return_const(Ok(res));
|
||||||
|
} else {
|
||||||
|
m.expect_mark_user_verified().return_const(Ok(res));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sync::Arc::new(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue