Added unit tests for pure logic. Refs #2
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+83
-1
@@ -259,4 +259,86 @@ impl ForValidation for UpdateMessage {
|
||||
fn entity(&self) -> &dyn Validate {
|
||||
&self.message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "ssr"))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use chrono::{NaiveDate, NaiveTime};
|
||||
use crate::backend::data::{Reservation, ResProperty, ResWithProperty};
|
||||
|
||||
fn reservation() -> ResSumWithItems {
|
||||
let mut property = ResProperty::default();
|
||||
property.name = "Court 1".to_string();
|
||||
|
||||
let mut reservation = ResSumWithItems::default();
|
||||
reservation.summary.date = NaiveDate::from_ymd_opt(2030, 3, 5).unwrap();
|
||||
reservation.reservations.push(ResWithProperty {
|
||||
reservation: Reservation::new(
|
||||
NaiveTime::from_hms_opt(8, 0, 0).unwrap(),
|
||||
NaiveTime::from_hms_opt(9, 30, 0).unwrap(),
|
||||
1),
|
||||
property
|
||||
});
|
||||
|
||||
reservation
|
||||
}
|
||||
|
||||
fn message(subject: &str, text: &str) -> Message {
|
||||
let mut message = Message::default();
|
||||
message.subject = subject.to_string();
|
||||
message.text = text.to_string();
|
||||
|
||||
message
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mail_message_replaces_variables() {
|
||||
let mail = MailMessage::new(
|
||||
"[email protected]".to_string(),
|
||||
"[email protected]".to_string(),
|
||||
message("Booking", "Date: #date#, items: #summary#."),
|
||||
&reservation());
|
||||
|
||||
assert_eq!(mail.subject, "Booking");
|
||||
assert_eq!(mail.text, "Date: 05. 03. 2030, items: Court 1: 08:00 - 09:30.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mail_message_without_variables_is_unchanged() {
|
||||
let mail = MailMessage::new(
|
||||
"[email protected]".to_string(),
|
||||
"[email protected]".to_string(),
|
||||
message("Booking", "Plain text"),
|
||||
&reservation());
|
||||
|
||||
assert_eq!(mail.text, "Plain text");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_mail_sets_headers() {
|
||||
let mail = MailMessage::new(
|
||||
"[email protected]".to_string(),
|
||||
"[email protected]".to_string(),
|
||||
message("Booking", "Hello"),
|
||||
&reservation());
|
||||
|
||||
let built = String::from_utf8(mail.build_mail("[email protected]".to_string()).unwrap().formatted()).unwrap();
|
||||
|
||||
assert!(built.contains("From: [email protected]"));
|
||||
assert!(built.contains("Reply-To: [email protected]"));
|
||||
assert!(built.contains("To: [email protected]"));
|
||||
assert!(built.contains("Subject: Booking"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_mail_rejects_invalid_address() {
|
||||
let mail = MailMessage::new(
|
||||
"[email protected]".to_string(),
|
||||
"not an address".to_string(),
|
||||
message("Booking", "Hello"),
|
||||
&reservation());
|
||||
|
||||
assert!(matches!(mail.build_mail("[email protected]".to_string()), Err(AppError::MailAddrParseErr(_))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user