Use the crate mockall to mock the email service in integration tests
This commit is contained in:
parent
3626f8a11b
commit
8c70f90234
5 changed files with 109 additions and 23 deletions
|
|
@ -1,23 +1,20 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use recipes::email;
|
||||
use async_trait::async_trait;
|
||||
use mockall::{mock, predicate::*};
|
||||
|
||||
pub struct MockEmailService;
|
||||
use crate::email;
|
||||
|
||||
impl MockEmailService {
|
||||
pub fn create_service() -> Arc<dyn email::EmailServiceTrait> {
|
||||
Arc::new(Self {})
|
||||
mock! {
|
||||
pub EmailService {}
|
||||
#[async_trait]
|
||||
impl email::EmailServiceTrait for EmailService {
|
||||
async fn send_email(&self, email: &str, title: &str, message: &str)
|
||||
-> Result<(), email::Error>;
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl email::EmailServiceTrait for MockEmailService {
|
||||
async fn send_email(
|
||||
&self,
|
||||
_email: &str,
|
||||
_title: &str,
|
||||
_message: &str,
|
||||
) -> Result<(), email::Error> {
|
||||
Ok(())
|
||||
}
|
||||
// Default email service: will crash if `send_email` method is called.
|
||||
pub fn new_mock_email_service() -> Arc<dyn email::EmailServiceTrait> {
|
||||
Arc::new(MockEmailService::new())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue