mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
Fix all tests
This commit is contained in:
@@ -682,7 +682,7 @@ mod tests {
|
|||||||
let test_id = Contact::create(&t, "", "bob@example.org").await?;
|
let test_id = Contact::create(&t, "", "bob@example.org").await?;
|
||||||
assert_eq!(contact_id, test_id);
|
assert_eq!(contact_id, test_id);
|
||||||
let chat = Chat::load_from_db(&t, chat_id).await?;
|
let chat = Chat::load_from_db(&t, chat_id).await?;
|
||||||
assert_eq!(chat.get_name(), "Bob Authname");
|
assert_eq!(chat.get_name(), "~Bob Authname");
|
||||||
let chats = Chatlist::try_load(&t, 0, Some("bob authname"), None).await?;
|
let chats = Chatlist::try_load(&t, 0, Some("bob authname"), None).await?;
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
let chats = Chatlist::try_load(&t, 0, Some("bob nickname"), None).await?;
|
let chats = Chatlist::try_load(&t, 0, Some("bob nickname"), None).await?;
|
||||||
|
|||||||
@@ -510,14 +510,6 @@ impl Origin {
|
|||||||
pub fn is_known(self) -> bool {
|
pub fn is_known(self) -> bool {
|
||||||
self >= Origin::IncomingReplyTo
|
self >= Origin::IncomingReplyTo
|
||||||
}
|
}
|
||||||
|
|
||||||
fn displayname_prefix(self) -> &'static str {
|
|
||||||
if self == Origin::ManuallyCreated {
|
|
||||||
""
|
|
||||||
} else {
|
|
||||||
"~"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
@@ -886,7 +878,7 @@ impl Contact {
|
|||||||
row_origin
|
row_origin
|
||||||
};
|
};
|
||||||
let new_authname = if update_authname {
|
let new_authname = if update_authname {
|
||||||
name.to_string()
|
name
|
||||||
} else {
|
} else {
|
||||||
row_authname
|
row_authname
|
||||||
};
|
};
|
||||||
@@ -915,11 +907,10 @@ impl Contact {
|
|||||||
).optional()?;
|
).optional()?;
|
||||||
|
|
||||||
if let Some(chat_id) = chat_id {
|
if let Some(chat_id) = chat_id {
|
||||||
let prefix = origin.displayname_prefix();
|
|
||||||
let chat_name = if !new_name.is_empty() {
|
let chat_name = if !new_name.is_empty() {
|
||||||
format!("{prefix}{}", new_name)
|
new_name
|
||||||
} else if !new_authname.is_empty() {
|
} else if !new_authname.is_empty() {
|
||||||
format!("{prefix}{}", new_authname)
|
format!("~{}", new_authname)
|
||||||
} else {
|
} else {
|
||||||
addr.to_string()
|
addr.to_string()
|
||||||
};
|
};
|
||||||
@@ -1364,12 +1355,11 @@ impl Contact {
|
|||||||
/// This name is typically used in lists.
|
/// This name is typically used in lists.
|
||||||
/// To get the name editable in a formular, use `Contact::get_name`.
|
/// To get the name editable in a formular, use `Contact::get_name`.
|
||||||
pub fn get_display_name(&self) -> String {
|
pub fn get_display_name(&self) -> String {
|
||||||
let prefix = self.origin.displayname_prefix();
|
|
||||||
if !self.name.is_empty() {
|
if !self.name.is_empty() {
|
||||||
return format!("{prefix}{}", self.name);
|
return self.name.clone();
|
||||||
}
|
}
|
||||||
if !self.authname.is_empty() {
|
if !self.authname.is_empty() {
|
||||||
return format!("{prefix}{}", self.authname);
|
return format!("~{}", self.authname);
|
||||||
}
|
}
|
||||||
self.addr.clone()
|
self.addr.clone()
|
||||||
}
|
}
|
||||||
@@ -1400,11 +1390,10 @@ impl Contact {
|
|||||||
/// The summary is typically used when asking the user something about the contact.
|
/// The summary is typically used when asking the user something about the contact.
|
||||||
/// The attached email address makes the question unique, eg. "Chat with Alan Miller (am@uniquedomain.com)?"
|
/// The attached email address makes the question unique, eg. "Chat with Alan Miller (am@uniquedomain.com)?"
|
||||||
pub fn get_name_n_addr(&self) -> String {
|
pub fn get_name_n_addr(&self) -> String {
|
||||||
let prefix = self.origin.displayname_prefix();
|
|
||||||
if !self.name.is_empty() {
|
if !self.name.is_empty() {
|
||||||
format!("{prefix}{} ({})", self.name, self.addr)
|
format!("{} ({})", self.name, self.addr)
|
||||||
} else if !self.authname.is_empty() {
|
} else if !self.authname.is_empty() {
|
||||||
format!("{prefix}{} ({})", self.authname, self.addr)
|
format!("~{} ({})", self.authname, self.addr)
|
||||||
} else {
|
} else {
|
||||||
(&self.addr).into()
|
(&self.addr).into()
|
||||||
}
|
}
|
||||||
@@ -2110,7 +2099,6 @@ mod tests {
|
|||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_add_or_lookup() {
|
async fn test_add_or_lookup() {
|
||||||
// add some contacts, this also tests add_address_book()
|
// add some contacts, this also tests add_address_book()
|
||||||
// TODO it's unsure whether we should put a ~ in front of these.
|
|
||||||
let t = TestContext::new().await;
|
let t = TestContext::new().await;
|
||||||
let book = concat!(
|
let book = concat!(
|
||||||
" Name one \n one@eins.org \n",
|
" Name one \n one@eins.org \n",
|
||||||
@@ -2137,9 +2125,9 @@ mod tests {
|
|||||||
assert_eq!(contact.get_id(), contact_id);
|
assert_eq!(contact.get_id(), contact_id);
|
||||||
assert_eq!(contact.get_name(), "Name one");
|
assert_eq!(contact.get_name(), "Name one");
|
||||||
assert_eq!(contact.get_authname(), "bla foo");
|
assert_eq!(contact.get_authname(), "bla foo");
|
||||||
assert_eq!(contact.get_display_name(), "~Name one");
|
assert_eq!(contact.get_display_name(), "Name one");
|
||||||
assert_eq!(contact.get_addr(), "one@eins.org");
|
assert_eq!(contact.get_addr(), "one@eins.org");
|
||||||
assert_eq!(contact.get_name_n_addr(), "~Name one (one@eins.org)");
|
assert_eq!(contact.get_name_n_addr(), "Name one (one@eins.org)");
|
||||||
|
|
||||||
// modify first added contact
|
// modify first added contact
|
||||||
let (contact_id_test, sth_modified) = Contact::add_or_lookup(
|
let (contact_id_test, sth_modified) = Contact::add_or_lookup(
|
||||||
@@ -2218,9 +2206,9 @@ mod tests {
|
|||||||
assert_eq!(sth_modified, Modifier::None);
|
assert_eq!(sth_modified, Modifier::None);
|
||||||
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
|
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
|
||||||
assert_eq!(contact.get_name(), "Wonderland, Alice");
|
assert_eq!(contact.get_name(), "Wonderland, Alice");
|
||||||
assert_eq!(contact.get_display_name(), "~Wonderland, Alice");
|
assert_eq!(contact.get_display_name(), "Wonderland, Alice");
|
||||||
assert_eq!(contact.get_addr(), "alice@w.de");
|
assert_eq!(contact.get_addr(), "alice@w.de");
|
||||||
assert_eq!(contact.get_name_n_addr(), "~Wonderland, Alice (alice@w.de)");
|
assert_eq!(contact.get_name_n_addr(), "Wonderland, Alice (alice@w.de)");
|
||||||
|
|
||||||
// check SELF
|
// check SELF
|
||||||
let contact = Contact::get_by_id(&t, ContactId::SELF).await.unwrap();
|
let contact = Contact::get_by_id(&t, ContactId::SELF).await.unwrap();
|
||||||
@@ -2511,8 +2499,7 @@ mod tests {
|
|||||||
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
|
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
|
||||||
assert_eq!(contact.get_authname(), "claire1");
|
assert_eq!(contact.get_authname(), "claire1");
|
||||||
assert_eq!(contact.get_name(), "");
|
assert_eq!(contact.get_name(), "");
|
||||||
println!("dbg/TODO {:?}", contact.origin);
|
assert_eq!(contact.get_display_name(), "~claire1");
|
||||||
assert_eq!(contact.get_display_name(), "~claire1"); // TODO this NEEDS to be "~claire1"
|
|
||||||
|
|
||||||
// incoming mail `From: claire2 <claire@example.org>` - this should update authname
|
// incoming mail `From: claire2 <claire@example.org>` - this should update authname
|
||||||
let (contact_id_same, sth_modified) = Contact::add_or_lookup(
|
let (contact_id_same, sth_modified) = Contact::add_or_lookup(
|
||||||
@@ -2528,7 +2515,7 @@ mod tests {
|
|||||||
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
|
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
|
||||||
assert_eq!(contact.get_authname(), "claire2");
|
assert_eq!(contact.get_authname(), "claire2");
|
||||||
assert_eq!(contact.get_name(), "");
|
assert_eq!(contact.get_name(), "");
|
||||||
assert_eq!(contact.get_display_name(), "claire2");
|
assert_eq!(contact.get_display_name(), "~claire2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Regression test.
|
/// Regression test.
|
||||||
@@ -2612,7 +2599,7 @@ mod tests {
|
|||||||
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
|
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
|
||||||
assert_eq!(contact.get_authname(), "dave2");
|
assert_eq!(contact.get_authname(), "dave2");
|
||||||
assert_eq!(contact.get_name(), "");
|
assert_eq!(contact.get_name(), "");
|
||||||
assert_eq!(contact.get_display_name(), "dave2");
|
assert_eq!(contact.get_display_name(), "~dave2");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1080,7 +1080,7 @@ mod tests {
|
|||||||
assert_eq!(contact.get_addr(), "stress@test.local");
|
assert_eq!(contact.get_addr(), "stress@test.local");
|
||||||
assert_eq!(contact.get_name(), "First Last");
|
assert_eq!(contact.get_name(), "First Last");
|
||||||
assert_eq!(contact.get_authname(), "");
|
assert_eq!(contact.get_authname(), "");
|
||||||
assert_eq!(contact.get_display_name(), "~First Last");
|
assert_eq!(contact.get_display_name(), "First Last");
|
||||||
assert!(draft.is_none());
|
assert!(draft.is_none());
|
||||||
} else {
|
} else {
|
||||||
bail!("Wrong QR code type");
|
bail!("Wrong QR code type");
|
||||||
|
|||||||
@@ -947,7 +947,6 @@ async fn test_no_unencrypted_name_if_encrypted() -> Result<()> {
|
|||||||
|
|
||||||
let msg = alice.recv_msg(msg).await;
|
let msg = alice.recv_msg(msg).await;
|
||||||
let contact = Contact::get_by_id(&alice, msg.from_id).await?;
|
let contact = Contact::get_by_id(&alice, msg.from_id).await?;
|
||||||
println!("dbg/TODO origin: {:?}", contact.origin);
|
|
||||||
assert_eq!(Contact::get_display_name(&contact), "~Bob Smith");
|
assert_eq!(Contact::get_display_name(&contact), "~Bob Smith");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user