mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
rustfmt
This commit is contained in:
24
src/blob.rs
24
src/blob.rs
@@ -536,36 +536,28 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn test_lowercase_ext() {
|
||||
let t = TestContext::new().await;
|
||||
let blob = BlobObject::create(&t, "foo.TXT", b"hello")
|
||||
.await
|
||||
.unwrap();
|
||||
let blob = BlobObject::create(&t, "foo.TXT", b"hello").await.unwrap();
|
||||
assert_eq!(blob.as_name(), "$BLOBDIR/foo.txt");
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_as_file_name() {
|
||||
let t = TestContext::new().await;
|
||||
let blob = BlobObject::create(&t, "foo.txt", b"hello")
|
||||
.await
|
||||
.unwrap();
|
||||
let blob = BlobObject::create(&t, "foo.txt", b"hello").await.unwrap();
|
||||
assert_eq!(blob.as_file_name(), "foo.txt");
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_as_rel_path() {
|
||||
let t = TestContext::new().await;
|
||||
let blob = BlobObject::create(&t, "foo.txt", b"hello")
|
||||
.await
|
||||
.unwrap();
|
||||
let blob = BlobObject::create(&t, "foo.txt", b"hello").await.unwrap();
|
||||
assert_eq!(blob.as_rel_path(), Path::new("foo.txt"));
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_suffix() {
|
||||
let t = TestContext::new().await;
|
||||
let blob = BlobObject::create(&t, "foo.txt", b"hello")
|
||||
.await
|
||||
.unwrap();
|
||||
let blob = BlobObject::create(&t, "foo.txt", b"hello").await.unwrap();
|
||||
assert_eq!(blob.suffix(), Some("txt"));
|
||||
let blob = BlobObject::create(&t, "bar", b"world").await.unwrap();
|
||||
assert_eq!(blob.suffix(), None);
|
||||
@@ -574,14 +566,10 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn test_create_dup() {
|
||||
let t = TestContext::new().await;
|
||||
BlobObject::create(&t, "foo.txt", b"hello")
|
||||
.await
|
||||
.unwrap();
|
||||
BlobObject::create(&t, "foo.txt", b"hello").await.unwrap();
|
||||
let foo_path = t.get_blobdir().join("foo.txt");
|
||||
assert!(foo_path.exists().await);
|
||||
BlobObject::create(&t, "foo.txt", b"world")
|
||||
.await
|
||||
.unwrap();
|
||||
BlobObject::create(&t, "foo.txt", b"world").await.unwrap();
|
||||
let mut dir = fs::read_dir(t.get_blobdir()).await.unwrap();
|
||||
while let Some(dirent) = dir.next().await {
|
||||
let fname = dirent.unwrap().file_name();
|
||||
|
||||
@@ -463,9 +463,7 @@ mod tests {
|
||||
assert_eq!(chats.get_chat_id(0), chat_id2);
|
||||
|
||||
// check chatlist query and archive functionality
|
||||
let chats = Chatlist::try_load(&t, 0, Some("b"), None)
|
||||
.await
|
||||
.unwrap();
|
||||
let chats = Chatlist::try_load(&t, 0, Some("b"), None).await.unwrap();
|
||||
assert_eq!(chats.len(), 1);
|
||||
|
||||
let chats = Chatlist::try_load(&t, DC_GCL_ARCHIVED_ONLY, None, None)
|
||||
@@ -522,8 +520,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(chats.len(), 0);
|
||||
|
||||
t
|
||||
.set_stock_translation(StockMessage::SavedMessages, "test-1234-save".to_string())
|
||||
t.set_stock_translation(StockMessage::SavedMessages, "test-1234-save".to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
let chats = Chatlist::try_load(&t, 0, Some("t-1234-s"), None)
|
||||
@@ -531,8 +528,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(chats.len(), 1);
|
||||
|
||||
t
|
||||
.set_stock_translation(StockMessage::DeviceMessages, "test-5678-babbel".to_string())
|
||||
t.set_stock_translation(StockMessage::DeviceMessages, "test-5678-babbel".to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
let chats = Chatlist::try_load(&t, 0, Some("t-5678-b"), None)
|
||||
|
||||
@@ -321,8 +321,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let avatar_blob = t.get_blobdir().join("avatar.jpg");
|
||||
assert!(!avatar_blob.exists().await);
|
||||
t
|
||||
.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
|
||||
t.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(avatar_blob.exists().await);
|
||||
@@ -353,8 +352,7 @@ mod tests {
|
||||
assert_eq!(img.width(), 900);
|
||||
assert_eq!(img.height(), 900);
|
||||
|
||||
t
|
||||
.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
|
||||
t.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
|
||||
.await
|
||||
.unwrap();
|
||||
let avatar_cfg = t.get_config(Config::Selfavatar).await;
|
||||
@@ -376,8 +374,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let avatar_blob = t.get_blobdir().join("avatar.png");
|
||||
assert!(!avatar_blob.exists().await);
|
||||
t
|
||||
.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
|
||||
t.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(avatar_blob.exists().await);
|
||||
@@ -397,10 +394,7 @@ mod tests {
|
||||
let media_quality = constants::MediaQuality::from_i32(media_quality).unwrap_or_default();
|
||||
assert_eq!(media_quality, constants::MediaQuality::Balanced);
|
||||
|
||||
t
|
||||
.set_config(Config::MediaQuality, Some("1"))
|
||||
.await
|
||||
.unwrap();
|
||||
t.set_config(Config::MediaQuality, Some("1")).await.unwrap();
|
||||
|
||||
let media_quality = t.get_config_int(Config::MediaQuality).await;
|
||||
assert_eq!(media_quality, 1);
|
||||
|
||||
@@ -616,14 +616,10 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn test_no_panic_on_bad_credentials() {
|
||||
let t = TestContext::new().await;
|
||||
t
|
||||
.set_config(Config::Addr, Some("probably@unexistant.addr"))
|
||||
.await
|
||||
.unwrap();
|
||||
t
|
||||
.set_config(Config::MailPw, Some("123456"))
|
||||
t.set_config(Config::Addr, Some("probably@unexistant.addr"))
|
||||
.await
|
||||
.unwrap();
|
||||
t.set_config(Config::MailPw, Some("123456")).await.unwrap();
|
||||
assert!(t.configure().await.is_err());
|
||||
}
|
||||
|
||||
|
||||
@@ -2056,10 +2056,7 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn test_adhoc_group_show_accepted_contact_unknown() {
|
||||
let t = TestContext::new_alice().await;
|
||||
t
|
||||
.set_config(Config::ShowEmails, Some("1"))
|
||||
.await
|
||||
.unwrap();
|
||||
t.set_config(Config::ShowEmails, Some("1")).await.unwrap();
|
||||
dc_receive_imf(&t, GRP_MAIL, "INBOX", 1, false)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -2072,13 +2069,8 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn test_adhoc_group_show_accepted_contact_known() {
|
||||
let t = TestContext::new_alice().await;
|
||||
t
|
||||
.set_config(Config::ShowEmails, Some("1"))
|
||||
.await
|
||||
.unwrap();
|
||||
Contact::create(&t, "Bob", "bob@example.com")
|
||||
.await
|
||||
.unwrap();
|
||||
t.set_config(Config::ShowEmails, Some("1")).await.unwrap();
|
||||
Contact::create(&t, "Bob", "bob@example.com").await.unwrap();
|
||||
dc_receive_imf(&t, GRP_MAIL, "INBOX", 1, false)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -2092,10 +2084,7 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn test_adhoc_group_show_accepted_contact_accepted() {
|
||||
let t = TestContext::new_alice().await;
|
||||
t
|
||||
.set_config(Config::ShowEmails, Some("1"))
|
||||
.await
|
||||
.unwrap();
|
||||
t.set_config(Config::ShowEmails, Some("1")).await.unwrap();
|
||||
|
||||
// accept Bob by accepting a delta-message from Bob
|
||||
dc_receive_imf(&t, MSGRMSG, "INBOX", 1, false)
|
||||
@@ -2138,10 +2127,7 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn test_adhoc_group_show_all() {
|
||||
let t = TestContext::new_alice().await;
|
||||
t
|
||||
.set_config(Config::ShowEmails, Some("2"))
|
||||
.await
|
||||
.unwrap();
|
||||
t.set_config(Config::ShowEmails, Some("2")).await.unwrap();
|
||||
dc_receive_imf(&t, GRP_MAIL, "INBOX", 1, false)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -2164,9 +2150,7 @@ mod tests {
|
||||
// create alice's account
|
||||
let t = TestContext::new_alice().await;
|
||||
|
||||
let bob_id = Contact::create(&t, "bob", "bob@example.com")
|
||||
.await
|
||||
.unwrap();
|
||||
let bob_id = Contact::create(&t, "bob", "bob@example.com").await.unwrap();
|
||||
let one2one_id = chat::create_by_contact_id(&t, bob_id).await.unwrap();
|
||||
one2one_id
|
||||
.set_visibility(&t, ChatVisibility::Archived)
|
||||
@@ -2180,10 +2164,7 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
chat::add_contact_to_chat(&t, group_id, bob_id).await;
|
||||
assert_eq!(
|
||||
chat::get_chat_msgs(&t, group_id, 0, None).await.len(),
|
||||
0
|
||||
);
|
||||
assert_eq!(chat::get_chat_msgs(&t, group_id, 0, None).await.len(), 0);
|
||||
group_id
|
||||
.set_visibility(&t, ChatVisibility::Archived)
|
||||
.await
|
||||
@@ -2231,9 +2212,7 @@ mod tests {
|
||||
} else {
|
||||
panic!("Wrong item type");
|
||||
};
|
||||
let msg = message::Message::load_from_db(&t, *msg_id)
|
||||
.await
|
||||
.unwrap();
|
||||
let msg = message::Message::load_from_db(&t, *msg_id).await.unwrap();
|
||||
assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
|
||||
assert_eq!(msg.text.unwrap(), "hello");
|
||||
assert_eq!(msg.state, MessageState::OutDelivered);
|
||||
@@ -2278,13 +2257,8 @@ mod tests {
|
||||
false,
|
||||
)
|
||||
.await.unwrap();
|
||||
assert_eq!(
|
||||
chat::get_chat_msgs(&t, group_id, 0, None).await.len(),
|
||||
1
|
||||
);
|
||||
let msg = message::Message::load_from_db(&t, *msg_id)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(chat::get_chat_msgs(&t, group_id, 0, None).await.len(), 1);
|
||||
let msg = message::Message::load_from_db(&t, *msg_id).await.unwrap();
|
||||
assert_eq!(msg.state, MessageState::OutMdnRcvd);
|
||||
|
||||
// check, the read-receipt has not unarchived the one2one
|
||||
@@ -2338,9 +2312,7 @@ mod tests {
|
||||
let contact_id = Contact::create(&t, "foobar", "foobar@example.com")
|
||||
.await
|
||||
.unwrap();
|
||||
let chat_id = chat::create_by_contact_id(&t, contact_id)
|
||||
.await
|
||||
.unwrap();
|
||||
let chat_id = chat::create_by_contact_id(&t, contact_id).await.unwrap();
|
||||
dc_receive_imf(
|
||||
&t,
|
||||
b"From: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= <foobar@example.com>\n\
|
||||
@@ -2370,9 +2342,7 @@ mod tests {
|
||||
} else {
|
||||
panic!("Wrong item type");
|
||||
};
|
||||
let msg = message::Message::load_from_db(&t, *msg_id)
|
||||
.await
|
||||
.unwrap();
|
||||
let msg = message::Message::load_from_db(&t, *msg_id).await.unwrap();
|
||||
assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
|
||||
assert_eq!(msg.text.unwrap(), "hello");
|
||||
assert_eq!(msg.param.get_int(Param::WantsMdn).unwrap(), 1);
|
||||
@@ -2433,15 +2403,11 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let carl_contact_id = Contact::add_or_lookup(
|
||||
&t,
|
||||
"garabage",
|
||||
"carl@host.tld",
|
||||
Origin::IncomingUnknownFrom,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
let carl_contact_id =
|
||||
Contact::add_or_lookup(&t, "garabage", "carl@host.tld", Origin::IncomingUnknownFrom)
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
|
||||
dc_receive_imf(
|
||||
&t,
|
||||
@@ -2624,9 +2590,7 @@ mod tests {
|
||||
let msg_id = chats.get_msg_id(0).unwrap();
|
||||
|
||||
let raw = include_bytes!("../test-data/message/gmail_ndn_group.eml");
|
||||
dc_receive_imf(&t, raw, "INBOX", 1, false)
|
||||
.await
|
||||
.unwrap();
|
||||
dc_receive_imf(&t, raw, "INBOX", 1, false).await.unwrap();
|
||||
|
||||
let msg = Message::load_from_db(&t, msg_id).await.unwrap();
|
||||
|
||||
@@ -2643,12 +2607,11 @@ mod tests {
|
||||
assert_eq!(
|
||||
last_msg.text,
|
||||
Some(
|
||||
t
|
||||
.stock_string_repl_str(
|
||||
StockMessage::FailedSendingTo,
|
||||
"assidhfaaspocwaeofi@gmail.com",
|
||||
)
|
||||
.await,
|
||||
t.stock_string_repl_str(
|
||||
StockMessage::FailedSendingTo,
|
||||
"assidhfaaspocwaeofi@gmail.com",
|
||||
)
|
||||
.await,
|
||||
)
|
||||
);
|
||||
assert_eq!(last_msg.from_id, DC_CONTACT_ID_INFO);
|
||||
@@ -2670,11 +2633,7 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn test_html_only_mail() {
|
||||
let t = TestContext::new_alice().await;
|
||||
let msg = load_imf_email(
|
||||
&t,
|
||||
include_bytes!("../test-data/message/wrong-html.eml"),
|
||||
)
|
||||
.await;
|
||||
let msg = load_imf_email(&t, include_bytes!("../test-data/message/wrong-html.eml")).await;
|
||||
assert_eq!(msg.text.unwrap(), " Guten Abend, \n\n Lots of text \n\n text with Umlaut ä... \n\n MfG [...]");
|
||||
}
|
||||
|
||||
|
||||
@@ -567,8 +567,7 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
|
||||
#[async_std::test]
|
||||
async fn test_load_self_generate_public() {
|
||||
let t = TestContext::new().await;
|
||||
t
|
||||
.set_config(Config::ConfiguredAddr, Some("alice@example.com"))
|
||||
t.set_config(Config::ConfiguredAddr, Some("alice@example.com"))
|
||||
.await
|
||||
.unwrap();
|
||||
let key = SignedPublicKey::load_self(&t).await;
|
||||
@@ -578,8 +577,7 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
|
||||
#[async_std::test]
|
||||
async fn test_load_self_generate_secret() {
|
||||
let t = TestContext::new().await;
|
||||
t
|
||||
.set_config(Config::ConfiguredAddr, Some("alice@example.com"))
|
||||
t.set_config(Config::ConfiguredAddr, Some("alice@example.com"))
|
||||
.await
|
||||
.unwrap();
|
||||
let key = SignedSecretKey::load_self(&t).await;
|
||||
@@ -591,8 +589,7 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
|
||||
use std::thread;
|
||||
|
||||
let t = TestContext::new().await;
|
||||
t
|
||||
.set_config(Config::ConfiguredAddr, Some("alice@example.com"))
|
||||
t.set_config(Config::ConfiguredAddr, Some("alice@example.com"))
|
||||
.await
|
||||
.unwrap();
|
||||
let ctx = t.clone();
|
||||
|
||||
@@ -1417,8 +1417,7 @@ mod tests {
|
||||
assert_eq!(first_subject_str(t).await, "Message from alice@example.com");
|
||||
|
||||
let t = TestContext::new_alice().await;
|
||||
t
|
||||
.set_config(Config::Displayname, Some("Alice"))
|
||||
t.set_config(Config::Displayname, Some("Alice"))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(first_subject_str(t).await, "Message from Alice");
|
||||
@@ -1492,9 +1491,7 @@ mod tests {
|
||||
Original-Message-ID: <2893@example.com>\n\
|
||||
Disposition: manual-action/MDN-sent-automatically; displayed\n\
|
||||
\n", &t).await;
|
||||
let mf = MimeFactory::from_msg(&t, &new_msg, false)
|
||||
.await
|
||||
.unwrap();
|
||||
let mf = MimeFactory::from_msg(&t, &new_msg, false).await.unwrap();
|
||||
// The subject string should not be "Re: message opened"
|
||||
assert_eq!("Re: Hello, Charlie", mf.subject_str().await);
|
||||
}
|
||||
@@ -1506,20 +1503,14 @@ mod tests {
|
||||
.unwrap()
|
||||
.0;
|
||||
|
||||
let chat_id = chat::create_by_contact_id(&t, contact_id)
|
||||
.await
|
||||
.unwrap();
|
||||
let chat_id = chat::create_by_contact_id(&t, contact_id).await.unwrap();
|
||||
|
||||
let mut new_msg = Message::new(Viewtype::Text);
|
||||
new_msg.set_text(Some("Hi".to_string()));
|
||||
new_msg.chat_id = chat_id;
|
||||
chat::prepare_msg(&t, chat_id, &mut new_msg)
|
||||
.await
|
||||
.unwrap();
|
||||
chat::prepare_msg(&t, chat_id, &mut new_msg).await.unwrap();
|
||||
|
||||
let mf = MimeFactory::from_msg(&t, &new_msg, false)
|
||||
.await
|
||||
.unwrap();
|
||||
let mf = MimeFactory::from_msg(&t, &new_msg, false).await.unwrap();
|
||||
|
||||
mf.subject_str().await
|
||||
}
|
||||
@@ -1527,9 +1518,7 @@ mod tests {
|
||||
async fn msg_to_subject_str(imf_raw: &[u8]) -> String {
|
||||
let t = TestContext::new_alice().await;
|
||||
let new_msg = incoming_msg_to_reply_msg(imf_raw, &t).await;
|
||||
let mf = MimeFactory::from_msg(&t, &new_msg, false)
|
||||
.await
|
||||
.unwrap();
|
||||
let mf = MimeFactory::from_msg(&t, &new_msg, false).await.unwrap();
|
||||
mf.subject_str().await
|
||||
}
|
||||
|
||||
|
||||
@@ -1793,9 +1793,7 @@ mod tests {
|
||||
let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml");
|
||||
let raw = String::from_utf8_lossy(raw).to_string();
|
||||
let raw = raw.replace("Chat-User-Avatar:", "Xhat-Xser-Xvatar:");
|
||||
let mimeparser = MimeMessage::from_bytes(&t, raw.as_bytes())
|
||||
.await
|
||||
.unwrap();
|
||||
let mimeparser = MimeMessage::from_bytes(&t, raw.as_bytes()).await.unwrap();
|
||||
assert_eq!(mimeparser.parts.len(), 1);
|
||||
assert_eq!(mimeparser.parts[0].typ, Viewtype::Image);
|
||||
assert_eq!(mimeparser.user_avatar, None);
|
||||
|
||||
28
src/param.rs
28
src/param.rs
@@ -476,36 +476,18 @@ mod tests {
|
||||
}
|
||||
|
||||
fs::write(fname, b"boo").await.unwrap();
|
||||
let blob = p
|
||||
.get_blob(Param::File, &t, true)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
blob,
|
||||
BlobObject::from_name(&t, "foo".to_string()).unwrap()
|
||||
);
|
||||
let blob = p.get_blob(Param::File, &t, true).await.unwrap().unwrap();
|
||||
assert_eq!(blob, BlobObject::from_name(&t, "foo".to_string()).unwrap());
|
||||
|
||||
// Blob in blobdir, expect blob.
|
||||
let bar_path = t.get_blobdir().join("bar");
|
||||
p.set(Param::File, bar_path.to_str().unwrap());
|
||||
let blob = p
|
||||
.get_blob(Param::File, &t, false)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
blob,
|
||||
BlobObject::from_name(&t, "bar".to_string()).unwrap()
|
||||
);
|
||||
let blob = p.get_blob(Param::File, &t, false).await.unwrap().unwrap();
|
||||
assert_eq!(blob, BlobObject::from_name(&t, "bar".to_string()).unwrap());
|
||||
|
||||
p.remove(Param::File);
|
||||
assert!(p.get_file(Param::File, &t).unwrap().is_none());
|
||||
assert!(p.get_path(Param::File, &t).unwrap().is_none());
|
||||
assert!(p
|
||||
.get_blob(Param::File, &t, false)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
assert!(p.get_blob(Param::File, &t, false).await.unwrap().is_none());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user