Fixed missing separator between booking items in mail summary. Fixes #5

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-10 17:19:33 +02:00
co-authored by Claude Opus 5.5
parent 11ace448ff
commit 15ee091a0a
+44 -18
View File
@@ -19,7 +19,6 @@ cfg_if! { if #[cfg(feature = "ssr")] {
use lettre::transport::smtp::client::{Tls, TlsParameters}; use lettre::transport::smtp::client::{Tls, TlsParameters};
use lettre::transport::smtp::authentication::Credentials; use lettre::transport::smtp::authentication::Credentials;
use lettre::transport::smtp::extension::ClientId; use lettre::transport::smtp::extension::ClientId;
use std::ops::Add;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::sync::mpsc; use std::sync::mpsc;
@@ -81,15 +80,12 @@ cfg_if! { if #[cfg(feature = "ssr")] {
fn replace_body_vars(text: String, reservation: &ResSumWithItems) -> String { fn replace_body_vars(text: String, reservation: &ResSumWithItems) -> String {
text text
.replace("#date#", &reservation.summary.date.format("%d. %m. %Y").to_string()) .replace("#date#", &reservation.summary.date.format("%d. %m. %Y").to_string())
.replace("#summary#", &{ .replace("#summary#", &reservation.reservations.iter()
let mut sum = "".to_string(); .map(|p| format!("{}: {} - {}",
for p in &reservation.reservations { p.property.name,
sum = sum.add(&format!("{}: {} - {}", p.reservation.from.format("%H:%M"), p.reservation.to.format("%H:%M")))
p.property.name, .collect::<Vec<_>>()
p.reservation.from.format("%H:%M").to_string(), p.reservation.to.format("%H:%M").to_string())); .join("\n")
}
sum
}
) )
} }
@@ -267,19 +263,23 @@ mod tests {
use chrono::{NaiveDate, NaiveTime}; use chrono::{NaiveDate, NaiveTime};
use crate::backend::data::{Reservation, ResProperty, ResWithProperty}; use crate::backend::data::{Reservation, ResProperty, ResWithProperty};
fn reservation() -> ResSumWithItems { fn item(name: &str, from: (u32, u32), to: (u32, u32)) -> ResWithProperty {
let mut property = ResProperty::default(); let mut property = ResProperty::default();
property.name = "Court 1".to_string(); property.name = name.to_string();
let mut reservation = ResSumWithItems::default(); ResWithProperty {
reservation.summary.date = NaiveDate::from_ymd_opt(2030, 3, 5).unwrap();
reservation.reservations.push(ResWithProperty {
reservation: Reservation::new( reservation: Reservation::new(
NaiveTime::from_hms_opt(8, 0, 0).unwrap(), NaiveTime::from_hms_opt(from.0, from.1, 0).unwrap(),
NaiveTime::from_hms_opt(9, 30, 0).unwrap(), NaiveTime::from_hms_opt(to.0, to.1, 0).unwrap(),
1), 1),
property property
}); }
}
fn reservation() -> ResSumWithItems {
let mut reservation = ResSumWithItems::default();
reservation.summary.date = NaiveDate::from_ymd_opt(2030, 3, 5).unwrap();
reservation.reservations.push(item("Court 1", (8, 0), (9, 30)));
reservation reservation
} }
@@ -304,6 +304,32 @@ mod tests {
assert_eq!(mail.text, "Date: 05. 03. 2030, items: Court 1: 08:00 - 09:30."); assert_eq!(mail.text, "Date: 05. 03. 2030, items: Court 1: 08:00 - 09:30.");
} }
#[test]
fn mail_message_summary_has_one_item_per_line() {
let mut reservation = reservation();
reservation.reservations.push(item("Court 2", (10, 0), (11, 0)));
reservation.reservations.push(item("Sauna", (18, 0), (20, 0)));
let mail = MailMessage::new(
"[email protected]".to_string(),
"[email protected]".to_string(),
message("Booking", "Items:\n#summary#\nBye"),
&reservation);
assert_eq!(mail.text, "Items:\nCourt 1: 08:00 - 09:30\nCourt 2: 10:00 - 11:00\nSauna: 18:00 - 20:00\nBye");
}
#[test]
fn mail_message_summary_is_empty_without_items() {
let mail = MailMessage::new(
"[email protected]".to_string(),
"[email protected]".to_string(),
message("Booking", "Items: #summary#."),
&ResSumWithItems::default());
assert_eq!(mail.text, "Items: .");
}
#[test] #[test]
fn mail_message_without_variables_is_unchanged() { fn mail_message_without_variables_is_unchanged() {
let mail = MailMessage::new( let mail = MailMessage::new(