use crate::assertion::DEFAULT_RECIPIENTS; use crate::helpers::{ new_message, TestInfoBuilder, DEFAULT_BODY, DEFAULT_RECIPIENT, DEFAULT_SENDER, }; use lettre::{transport::smtp::client::Tls, Transport}; use maik::MailAssertion; use std::collections::HashSet; #[test] fn sender_recipient_body() { let test_info = TestInfoBuilder::new().default_auth_user().build(); let mailer = test_info.mailer_builder.tls(Tls::None).build(); let message = new_message(DEFAULT_RECIPIENTS, DEFAULT_BODY); assert!(mailer.send(&message).is_ok()); let mut recipients = HashSet::new(); recipients.insert("r1@d.com"); recipients.insert("r2@d.com"); let ma = MailAssertion::new() .sender_is(DEFAULT_SENDER) .recipients_are(recipients) .body_is(DEFAULT_BODY); assert!(test_info.server.assert(ma)); } #[test] fn sender_body_but_with_recipients_from_another_mail() { let test_info = TestInfoBuilder::new().default_auth_user().build(); let mailer = test_info.mailer_builder.tls(Tls::None).build(); let message = new_message(DEFAULT_RECIPIENT, ""); assert!(mailer.send(&message).is_ok()); let message = new_message("someone_else@domain2.com", DEFAULT_BODY); assert!(mailer.send(&message).is_ok()); let mut recipients = HashSet::new(); recipients.insert(DEFAULT_RECIPIENT); let ma = MailAssertion::new() .sender_is(DEFAULT_SENDER) .recipients_are(recipients) .body_is(DEFAULT_BODY); assert!(!test_info.server.assert(ma)); }