Lines of
tests/mail.rs
from check-in b9af445709
that are changed by the sequence of edits moving toward
check-in 40a93e9a58:
1: use smtp2tg::mail::MailServer;
2:
3: use stacked_errors::{
4: Result,
5: StackableErr,
6: };
7:
8: use tgbot::types::ChatPeerId;
158c9cffc6 2026-08-01 9: /// Builds a `MailServer` purely from an in-memory TOML source, no
158c9cffc6 2026-08-01 10: /// network access is performed while constructing it.
158c9cffc6 2026-08-01 11: fn build_server () -> Result<MailServer> {
158c9cffc6 2026-08-01 12: let settings = config::Config::builder()
13: .add_source(config::File::from_str(r#"
14: api_key = "test-api-key"
15: api_gateway = "https://api.telegram.org"
16: default = 0
f748e99b70 2026-08-01 17: unknown = "relay"
18: fields = ["date", "from", "subject"]
19: domains = ["example.com"]
20:
21: [recipients]
22: "someone@example.com" = 1
23: "root" = -1
158c9cffc6 2026-08-01 24: "#, config::FileFormat::Toml))
25: .build()
158c9cffc6 2026-08-01 26: .stack()?;
158c9cffc6 2026-08-01 27: MailServer::new(settings)
158c9cffc6 2026-08-01 28: }
158c9cffc6 2026-08-01 29:
158c9cffc6 2026-08-01 30: #[test]
f748e99b70 2026-08-01 31: fn get_id_returns_configured_recipient () -> Result<()> {
158c9cffc6 2026-08-01 32: let server = build_server()?;
33: let cases = [
34: ("someone@example.com", 1),
35: ("someone", 0),
36: ("root", -1),
37: ("unknown@example.com", 0),
38: ];
39: for (email, id) in cases {
158c9cffc6 2026-08-01 40: assert_eq!(*server.get_id(email)?, ChatPeerId::from(id), "email [{email}] expected to return id [{id}]");
158c9cffc6 2026-08-01 41: }
42: Ok(())
43: }