mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Add test
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -932,7 +932,7 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "email"
|
name = "email"
|
||||||
version = "0.0.21"
|
version = "0.0.21"
|
||||||
source = "git+https://github.com/deltachat/rust-email#ace12ee6f8e054dd890589f588d0311604fc25f0"
|
source = "git+https://github.com/Hocuri/rust-email#6c903a5b1dd91acb191af2987ca29c28bb733c56"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.11.0",
|
"base64 0.11.0",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -1602,7 +1602,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "lettre"
|
name = "lettre"
|
||||||
version = "0.9.2"
|
version = "0.9.2"
|
||||||
source = "git+https://github.com/deltachat/lettre#12e4f22d8d691fb5d1606e4c9034f5d4d9ba635b"
|
source = "git+https://github.com/Hocuri/lettre#05a94e82269e3d85b7b7b5b88e779daf4f6343db"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fast_chemail",
|
"fast_chemail",
|
||||||
"log",
|
"log",
|
||||||
@@ -1611,7 +1611,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "lettre_email"
|
name = "lettre_email"
|
||||||
version = "0.9.2"
|
version = "0.9.2"
|
||||||
source = "git+https://github.com/deltachat/lettre#12e4f22d8d691fb5d1606e4c9034f5d4d9ba635b"
|
source = "git+https://github.com/Hocuri/lettre#05a94e82269e3d85b7b7b5b88e779daf4f6343db"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.11.0",
|
"base64 0.11.0",
|
||||||
"email",
|
"email",
|
||||||
|
|||||||
@@ -1780,7 +1780,7 @@ mod tests {
|
|||||||
use crate::chat::ChatVisibility;
|
use crate::chat::ChatVisibility;
|
||||||
use crate::chatlist::Chatlist;
|
use crate::chatlist::Chatlist;
|
||||||
use crate::message::Message;
|
use crate::message::Message;
|
||||||
use crate::test_utils::{dummy_context, TestContext};
|
use crate::test_utils::{configured_offline_context, dummy_context};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hex_hash() {
|
fn test_hex_hash() {
|
||||||
@@ -1876,23 +1876,6 @@ mod tests {
|
|||||||
assert!(!is_msgrmsg_rfc724_mid(&t.ctx, "nonexistant@message.id").await);
|
assert!(!is_msgrmsg_rfc724_mid(&t.ctx, "nonexistant@message.id").await);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn configured_offline_context() -> TestContext {
|
|
||||||
let t = dummy_context().await;
|
|
||||||
t.ctx
|
|
||||||
.set_config(Config::Addr, Some("alice@example.org"))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
t.ctx
|
|
||||||
.set_config(Config::ConfiguredAddr, Some("alice@example.org"))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
t.ctx
|
|
||||||
.set_config(Config::Configured, Some("1"))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
t
|
|
||||||
}
|
|
||||||
|
|
||||||
static MSGRMSG: &[u8] = b"From: Bob <bob@example.org>\n\
|
static MSGRMSG: &[u8] = b"From: Bob <bob@example.org>\n\
|
||||||
To: alice@example.org\n\
|
To: alice@example.org\n\
|
||||||
Chat-Version: 1.0\n\
|
Chat-Version: 1.0\n\
|
||||||
|
|||||||
@@ -1207,6 +1207,11 @@ pub fn needs_encoding(to_check: impl AsRef<str>) -> bool {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::chatlist::Chatlist;
|
||||||
|
use crate::dc_receive_imf::dc_receive_imf;
|
||||||
|
use crate::mimeparser::*;
|
||||||
|
use crate::test_utils::configured_offline_context;
|
||||||
|
use crate::test_utils::TestContext;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_render_email_address() {
|
fn test_render_email_address() {
|
||||||
@@ -1243,8 +1248,10 @@ mod tests {
|
|||||||
Address::new_mailbox_with_name(display_name.to_string(), addr.to_string())
|
Address::new_mailbox_with_name(display_name.to_string(), addr.to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Addresses should not be unnecessarily be encoded, see https://github.com/deltachat/deltachat-core-rust/issues/1575:
|
||||||
assert_eq!(s, "a space <x@y.org>");
|
assert_eq!(s, "a space <x@y.org>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_render_rfc724_mid() {
|
fn test_render_rfc724_mid() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -1288,25 +1295,6 @@ mod tests {
|
|||||||
assert!(needs_encoding("foo bar"));
|
assert!(needs_encoding("foo bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::test_utils::{dummy_context, TestContext};
|
|
||||||
|
|
||||||
async fn configured_offline_context() -> TestContext {
|
|
||||||
let t = dummy_context().await;
|
|
||||||
t.ctx
|
|
||||||
.set_config(Config::Addr, Some("alice@example.org"))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
t.ctx
|
|
||||||
.set_config(Config::ConfiguredAddr, Some("alice@example.org"))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
t.ctx
|
|
||||||
.set_config(Config::Configured, Some("1"))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
t
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_subject() {
|
async fn test_subject() {
|
||||||
// 1.: Receive a mail from an MUA or Delta Chat
|
// 1.: Receive a mail from an MUA or Delta Chat
|
||||||
@@ -1419,35 +1407,79 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn msg_to_subject_str(imf_raw: &[u8]) -> String {
|
async fn msg_to_subject_str(imf_raw: &[u8]) -> String {
|
||||||
use crate::chatlist::Chatlist;
|
|
||||||
use crate::dc_receive_imf::dc_receive_imf;
|
|
||||||
|
|
||||||
let t = configured_offline_context().await;
|
let t = configured_offline_context().await;
|
||||||
t.ctx
|
let new_msg = incoming_msg_to_reply_msg(imf_raw, &t.ctx).await;
|
||||||
|
let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
mf.subject_str().await
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates a mimefactory for a message that replies "Hi" to the incoming message in `imf_raw`.
|
||||||
|
async fn incoming_msg_to_reply_msg(imf_raw: &[u8], context: &Context) -> Message {
|
||||||
|
context
|
||||||
.set_config(Config::ShowEmails, Some("2"))
|
.set_config(Config::ShowEmails, Some("2"))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
dc_receive_imf(&t.ctx, imf_raw, "INBOX", 1, false)
|
dc_receive_imf(context, imf_raw, "INBOX", 1, false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(context, 0, None, None).await.unwrap();
|
||||||
|
|
||||||
let chat_id = chat::create_by_msg_id(&t.ctx, chats.get_msg_id(0).unwrap())
|
let chat_id = chat::create_by_msg_id(context, chats.get_msg_id(0).unwrap())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut new_msg = Message::new(Viewtype::Text);
|
let mut new_msg = Message::new(Viewtype::Text);
|
||||||
new_msg.set_text(Some("Hi".to_string()));
|
new_msg.set_text(Some("Hi".to_string()));
|
||||||
new_msg.chat_id = chat_id;
|
new_msg.chat_id = chat_id;
|
||||||
chat::prepare_msg(&t.ctx, chat_id, &mut new_msg)
|
chat::prepare_msg(context, chat_id, &mut new_msg)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false)
|
new_msg
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
// This test could still be extended
|
||||||
|
async fn test_render_reply() {
|
||||||
|
let t = configured_offline_context().await;
|
||||||
|
let context = &t.ctx;
|
||||||
|
|
||||||
|
let msg = incoming_msg_to_reply_msg(
|
||||||
|
b"From: Charlie <charlie@example.org>\n\
|
||||||
|
To: alice@example.org\n\
|
||||||
|
Subject: Chat: hello\n\
|
||||||
|
Chat-Version: 1.0\n\
|
||||||
|
Message-ID: <2223@example.org>\n\
|
||||||
|
Date: Sun, 22 Mar 2020 22:37:56 +0000\n\
|
||||||
|
\n\
|
||||||
|
hello\n",
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let mimefactory = MimeFactory::from_msg(&t.ctx, &msg, false).await.unwrap();
|
||||||
|
|
||||||
|
let recipients = mimefactory.recipients();
|
||||||
|
assert_eq!(recipients, vec!["charlie@example.org"]);
|
||||||
|
|
||||||
|
let rendered_msg = mimefactory.render().await.unwrap();
|
||||||
|
|
||||||
|
let mail = mailparse::parse_mail(&rendered_msg.message).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
mail.headers
|
||||||
|
.iter()
|
||||||
|
.find(|h| h.get_key() == "MIME-Version")
|
||||||
|
.unwrap()
|
||||||
|
.get_value(),
|
||||||
|
"1.0"
|
||||||
|
);
|
||||||
|
|
||||||
|
let _mime_msg = MimeMessage::from_bytes(context, &rendered_msg.message)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
mf.subject_str().await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,23 @@ pub(crate) async fn dummy_context() -> TestContext {
|
|||||||
test_context().await
|
test_context().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn configured_offline_context() -> TestContext {
|
||||||
|
let t = dummy_context().await;
|
||||||
|
t.ctx
|
||||||
|
.set_config(Config::Addr, Some("alice@example.org"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
t.ctx
|
||||||
|
.set_config(Config::ConfiguredAddr, Some("alice@example.org"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
t.ctx
|
||||||
|
.set_config(Config::Configured, Some("1"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
t
|
||||||
|
}
|
||||||
|
|
||||||
/// Load a pre-generated keypair for alice@example.com from disk.
|
/// Load a pre-generated keypair for alice@example.com from disk.
|
||||||
///
|
///
|
||||||
/// This saves CPU cycles by avoiding having to generate a key.
|
/// This saves CPU cycles by avoiding having to generate a key.
|
||||||
|
|||||||
Reference in New Issue
Block a user