Email/copy passing tests
This commit is contained in:
98
tests/src/jmap/email_copy.rs
Normal file
98
tests/src/jmap/email_copy.rs
Normal file
@@ -0,0 +1,98 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use jmap::JMAP;
|
||||
use jmap_client::{client::Client, mailbox::Role};
|
||||
use jmap_proto::types::id::Id;
|
||||
|
||||
pub async fn test(server: Arc<JMAP>, client: &mut Client) {
|
||||
println!("Running Email Copy tests...");
|
||||
|
||||
// Create a mailbox on account 1
|
||||
let ac1_mailbox_id = client
|
||||
.set_default_account_id(Id::new(1).to_string())
|
||||
.mailbox_create("Copy Test Ac# 1", None::<String>, Role::None)
|
||||
.await
|
||||
.unwrap()
|
||||
.take_id();
|
||||
|
||||
// Insert a message on account 1
|
||||
let ac1_email_id = client
|
||||
.email_import(
|
||||
concat!(
|
||||
"From: bill@example.com\r\n",
|
||||
"To: jdoe@example.com\r\n",
|
||||
"Subject: TPS Report\r\n",
|
||||
"\r\n",
|
||||
"I'm going to need those TPS reports ASAP. ",
|
||||
"So, if you could do that, that'd be great."
|
||||
)
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
[&ac1_mailbox_id],
|
||||
None::<Vec<&str>>,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.take_id();
|
||||
|
||||
// Create a mailbox on account 2
|
||||
let ac2_mailbox_id = client
|
||||
.set_default_account_id(Id::new(2).to_string())
|
||||
.mailbox_create("Copy Test Ac# 2", None::<String>, Role::None)
|
||||
.await
|
||||
.unwrap()
|
||||
.take_id();
|
||||
|
||||
// Copy the email and delete it from the first account
|
||||
let mut request = client.build();
|
||||
request
|
||||
.copy_email(Id::new(1).to_string())
|
||||
.on_success_destroy_original(true)
|
||||
.create(&ac1_email_id)
|
||||
.mailbox_id(&ac2_mailbox_id, true)
|
||||
.keyword("$draft", true)
|
||||
.received_at(311923920);
|
||||
let ac2_email_id = request
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.method_response_by_pos(0)
|
||||
.unwrap_copy_email()
|
||||
.unwrap()
|
||||
.created(&ac1_email_id)
|
||||
.unwrap()
|
||||
.take_id();
|
||||
|
||||
// Check that the email was copied
|
||||
let email = client
|
||||
.email_get(&ac2_email_id, None::<Vec<_>>)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
email.preview().unwrap(),
|
||||
"I'm going to need those TPS reports ASAP. So, if you could do that, that'd be great."
|
||||
);
|
||||
assert_eq!(email.subject().unwrap(), "TPS Report");
|
||||
assert_eq!(email.mailbox_ids(), &[&ac2_mailbox_id]);
|
||||
assert_eq!(email.keywords(), &["$draft"]);
|
||||
assert_eq!(email.received_at().unwrap(), 311923920);
|
||||
|
||||
// Check that the email was deleted
|
||||
assert!(client
|
||||
.set_default_account_id(Id::new(1).to_string())
|
||||
.email_get(&ac1_email_id, None::<Vec<_>>)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
|
||||
// Empty store
|
||||
client.mailbox_destroy(&ac1_mailbox_id, true).await.unwrap();
|
||||
client
|
||||
.set_default_account_id(Id::new(2).to_string())
|
||||
.mailbox_destroy(&ac2_mailbox_id, true)
|
||||
.await
|
||||
.unwrap();
|
||||
server.store.assert_is_empty().await;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use tokio::sync::watch;
|
||||
use crate::{add_test_certs, store::TempDir};
|
||||
|
||||
pub mod email_changes;
|
||||
pub mod email_copy;
|
||||
pub mod email_get;
|
||||
pub mod email_parse;
|
||||
pub mod email_query;
|
||||
@@ -65,7 +66,8 @@ pub async fn jmap_tests() {
|
||||
//email_parse::test(params.server.clone(), &mut params.client).await;
|
||||
//email_search_snippet::test(params.server.clone(), &mut params.client).await;
|
||||
//email_changes::test(params.server.clone(), &mut params.client).await;
|
||||
email_query_changes::test(params.server.clone(), &mut params.client).await;
|
||||
//email_query_changes::test(params.server.clone(), &mut params.client).await;
|
||||
email_copy::test(params.server.clone(), &mut params.client).await;
|
||||
//thread_get::test(params.server.clone(), &mut params.client).await;
|
||||
//thread_merge::test(params.server.clone(), &mut params.client).await;
|
||||
//mailbox::test(params.server.clone(), &mut params.client).await;
|
||||
|
||||
Reference in New Issue
Block a user