use crate::assertion::DEFAULT_RECIPIENTS; use crate::helpers::{ new_message, TestInfoBuilder, DEFAULT_BODY, DEFAULT_RECIPIENT, DEFAULT_SENDER, EMPTY_MESSAGE, }; use lettre::{transport::smtp::client::Tls, Transport}; use maik::MailAssertion; use std::collections::HashSet; #[test] fn sender_is() { let test_info = TestInfoBuilder::new().default_auth_user().build(); let mailer = test_info.mailer_builder.tls(Tls::None).build(); assert!(mailer.send(&EMPTY_MESSAGE).is_ok()); let ma = MailAssertion::new().sender_is(DEFAULT_SENDER); assert!(test_info.server.assert(ma)); } #[test] fn sender_is_not() { let test_info = TestInfoBuilder::new().default_auth_user().build(); let mailer = test_info.mailer_builder.tls(Tls::None).build(); assert!(mailer.send(&EMPTY_MESSAGE).is_ok()); let ma = MailAssertion::new().sender_is("user_dne"); assert!(!test_info.server.assert(ma)); } #[test] fn recipients_are_with_one_recipient() { let test_info = TestInfoBuilder::new().default_auth_user().build(); let mailer = test_info.mailer_builder.tls(Tls::None).build(); assert!(mailer.send(&EMPTY_MESSAGE).is_ok()); let mut recipients = HashSet::new(); recipients.insert(DEFAULT_RECIPIENT); let ma = MailAssertion::new().recipients_are(recipients); assert!(test_info.server.assert(ma)); } #[test] fn recipients_are_not_with_one_recipient() { let test_info = TestInfoBuilder::new().default_auth_user().build(); let mailer = test_info.mailer_builder.tls(Tls::None).build(); assert!(mailer.send(&EMPTY_MESSAGE).is_ok()); let mut recipients = HashSet::new(); recipients.insert("recipients_dne"); let ma = MailAssertion::new().recipients_are(recipients); assert!(!test_info.server.assert(ma)); } #[test] fn recipients_are_subset_with_one_recipient() { let test_info = TestInfoBuilder::new().default_auth_user().build(); let mailer = test_info.mailer_builder.tls(Tls::None).build(); assert!(mailer.send(&EMPTY_MESSAGE).is_ok()); let recipients = HashSet::new(); let ma = MailAssertion::new().recipients_are(recipients); assert!(!test_info.server.assert(ma)); } #[test] fn recipients_are_superset_with_one_recipient() { let test_info = TestInfoBuilder::new().default_auth_user().build(); let mailer = test_info.mailer_builder.tls(Tls::None).build(); assert!(mailer.send(&EMPTY_MESSAGE).is_ok()); let mut recipients = HashSet::new(); recipients.insert(DEFAULT_RECIPIENT); recipients.insert("recipients_dne"); let ma = MailAssertion::new().recipients_are(recipients); assert!(!test_info.server.assert(ma)); } #[test] fn recipients_are_with_multiple_recipients() { 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, ""); 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().recipients_are(recipients); assert!(test_info.server.assert(ma)); } #[test] fn recipients_are_not_with_multiple_recipients() { 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, ""); assert!(mailer.send(&message).is_ok()); let mut recipients = HashSet::new(); recipients.insert("r1@d.com"); recipients.insert("r3@d.com"); let ma = MailAssertion::new().recipients_are(recipients); assert!(!test_info.server.assert(ma)); } #[test] fn recipients_contain_subset() { 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, ""); assert!(mailer.send(&message).is_ok()); let mut recipients = HashSet::new(); recipients.insert("r1@d.com"); let ma = MailAssertion::new().recipients_contain(recipients); assert!(test_info.server.assert(ma)); } #[test] fn recipients_contain_equal() { 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, ""); 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().recipients_contain(recipients); assert!(test_info.server.assert(ma)); } #[test] fn recipients_contain_no_contain() { 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, ""); assert!(mailer.send(&message).is_ok()); let mut recipients = HashSet::new(); recipients.insert("r3@d.com"); let ma = MailAssertion::new().recipients_contain(recipients); assert!(!test_info.server.assert(ma)); } #[test] fn recipients_contain_supserset() { 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, ""); assert!(mailer.send(&message).is_ok()); let mut recipients = HashSet::new(); recipients.insert("r1@d.com"); recipients.insert("r2@d.com"); recipients.insert("r3@d.com"); let ma = MailAssertion::new().recipients_contain(recipients); assert!(!test_info.server.assert(ma)); } #[test] fn body_is() { 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, DEFAULT_BODY); assert!(mailer.send(&message).is_ok()); let ma = MailAssertion::new().body_is(DEFAULT_BODY); assert!(test_info.server.assert(ma)); } #[test] fn body_is_not() { 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, DEFAULT_BODY); assert!(mailer.send(&message).is_ok()); let ma = MailAssertion::new().body_is("no"); assert!(!test_info.server.assert(ma)); } #[test] fn body_contains() { 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, DEFAULT_BODY); assert!(mailer.send(&message).is_ok()); let ma = MailAssertion::new().body_contains("nana"); assert!(test_info.server.assert(ma)); } #[test] fn body_contains_no_contain() { 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, DEFAULT_BODY); assert!(mailer.send(&message).is_ok()); let ma = MailAssertion::new().body_contains("no"); assert!(!test_info.server.assert(ma)); }