Update dependencies and implement email service integration
- Refactor app and email modules to include email service - Add tests for user sign-up and mock email service
This commit is contained in:
parent
f31167dd95
commit
3626f8a11b
10 changed files with 291 additions and 151 deletions
|
|
@ -5,6 +5,7 @@ use cookie::Cookie;
|
|||
use scraper::{ElementRef, Html, Selector};
|
||||
|
||||
use recipes::app;
|
||||
use serde::Serialize;
|
||||
|
||||
mod utils;
|
||||
|
||||
|
|
@ -92,3 +93,36 @@ async fn user_edit() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct SignUpFormData {
|
||||
email: String,
|
||||
password_1: String,
|
||||
password_2: String,
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_up() -> Result<(), Box<dyn Error>> {
|
||||
// Arrange.
|
||||
let state = utils::common_state().await?;
|
||||
let server = TestServer::new(app::make_service(state))?;
|
||||
|
||||
// Act.
|
||||
let response = server
|
||||
.post("/signup")
|
||||
.form(&SignUpFormData {
|
||||
email: "president@spaceball.planet".into(),
|
||||
password_1: "12345678".into(),
|
||||
password_2: "12345678".into(),
|
||||
})
|
||||
.await;
|
||||
|
||||
// Assert.
|
||||
response.assert_status_ok();
|
||||
|
||||
let document = Html::parse_document(&response.text());
|
||||
assert_eq!(document.errors.len(), 0);
|
||||
dbg!(response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
23
backend/tests/utils/mock_email.rs
Normal file
23
backend/tests/utils/mock_email.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use recipes::email;
|
||||
|
||||
pub struct MockEmailService;
|
||||
|
||||
impl MockEmailService {
|
||||
pub fn create_service() -> Arc<dyn email::EmailServiceTrait> {
|
||||
Arc::new(Self {})
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl email::EmailServiceTrait for MockEmailService {
|
||||
async fn send_email(
|
||||
&self,
|
||||
_email: &str,
|
||||
_title: &str,
|
||||
_message: &str,
|
||||
) -> Result<(), email::Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@ use std::error::Error;
|
|||
|
||||
use recipes::{app, config, data::db, log};
|
||||
|
||||
mod mock_email;
|
||||
|
||||
pub async fn common_state() -> Result<app::AppState, Box<dyn Error>> {
|
||||
let db_connection = db::Connection::new_in_memory().await?;
|
||||
let config = config::Config::default();
|
||||
|
|
@ -10,6 +12,7 @@ pub async fn common_state() -> Result<app::AppState, Box<dyn Error>> {
|
|||
config,
|
||||
db_connection,
|
||||
log,
|
||||
email_service: mock_email::MockEmailService::create_service(),
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue