Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::utils::{
|
||||
jmap::{ChangeType, JmapUtils},
|
||||
server::TestServer,
|
||||
};
|
||||
use jmap_proto::{object::addressbook::AddressBookProperty, request::method::MethodObject};
|
||||
use serde_json::json;
|
||||
|
||||
pub async fn test(test: &TestServer) {
|
||||
println!("Running AddressBook tests...");
|
||||
let account = test.account("[email protected]");
|
||||
|
||||
// Make sure the default address book exists
|
||||
let response = account
|
||||
.jmap_get(
|
||||
MethodObject::AddressBook,
|
||||
[
|
||||
AddressBookProperty::Id,
|
||||
AddressBookProperty::Name,
|
||||
AddressBookProperty::Description,
|
||||
AddressBookProperty::SortOrder,
|
||||
AddressBookProperty::IsSubscribed,
|
||||
AddressBookProperty::IsDefault,
|
||||
],
|
||||
Vec::<&str>::new(),
|
||||
)
|
||||
.await;
|
||||
let list = response.list();
|
||||
assert_eq!(list.len(), 1);
|
||||
let default_addressbook_id = list[0].id().to_string();
|
||||
assert_eq!(
|
||||
list[0],
|
||||
json!({
|
||||
"name": "Stalwart Address Book ([email protected])",
|
||||
"description": (),
|
||||
"sortOrder": 0,
|
||||
"isSubscribed": true,
|
||||
"isDefault": true,
|
||||
"id": default_addressbook_id,
|
||||
})
|
||||
);
|
||||
let change_id = response.state();
|
||||
|
||||
// Create Address Book
|
||||
let addressbook_id = account
|
||||
.jmap_create(
|
||||
MethodObject::AddressBook,
|
||||
[json!({
|
||||
"name": "Test address book",
|
||||
"description": "My personal address book",
|
||||
"sortOrder": 1,
|
||||
"isSubscribed": true
|
||||
|
||||
})],
|
||||
Vec::<(&str, &str)>::new(),
|
||||
)
|
||||
.await
|
||||
.created(0)
|
||||
.id()
|
||||
.to_string();
|
||||
|
||||
// Validate changes
|
||||
assert_eq!(
|
||||
account
|
||||
.jmap_changes(MethodObject::AddressBook, change_id)
|
||||
.await
|
||||
.changes()
|
||||
.collect::<Vec<_>>(),
|
||||
[ChangeType::Created(&addressbook_id)]
|
||||
);
|
||||
|
||||
// Get Address Book
|
||||
let response = account
|
||||
.jmap_get(
|
||||
MethodObject::AddressBook,
|
||||
[
|
||||
AddressBookProperty::Id,
|
||||
AddressBookProperty::Name,
|
||||
AddressBookProperty::Description,
|
||||
AddressBookProperty::SortOrder,
|
||||
AddressBookProperty::IsSubscribed,
|
||||
AddressBookProperty::IsDefault,
|
||||
],
|
||||
[&addressbook_id],
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
response.list()[0],
|
||||
json!({
|
||||
"name": "Test address book",
|
||||
"description": "My personal address book",
|
||||
"sortOrder": 1,
|
||||
"isSubscribed": true,
|
||||
"isDefault": false,
|
||||
"id": addressbook_id,
|
||||
})
|
||||
);
|
||||
|
||||
// Update Address Book and set it as default
|
||||
account
|
||||
.jmap_update(
|
||||
MethodObject::AddressBook,
|
||||
[(
|
||||
addressbook_id.as_str(),
|
||||
json!({
|
||||
"name": "Updated address book",
|
||||
"description": "My updated personal address book",
|
||||
"sortOrder": 2,
|
||||
"isSubscribed": false
|
||||
}),
|
||||
)],
|
||||
[("onSuccessSetIsDefault", addressbook_id.as_str())],
|
||||
)
|
||||
.await
|
||||
.updated(&addressbook_id);
|
||||
|
||||
// Validate changes
|
||||
assert_eq!(
|
||||
account
|
||||
.jmap_get(
|
||||
MethodObject::AddressBook,
|
||||
[
|
||||
AddressBookProperty::Id,
|
||||
AddressBookProperty::Name,
|
||||
AddressBookProperty::Description,
|
||||
AddressBookProperty::SortOrder,
|
||||
AddressBookProperty::IsSubscribed,
|
||||
AddressBookProperty::IsDefault,
|
||||
],
|
||||
[&addressbook_id, &default_addressbook_id],
|
||||
)
|
||||
.await
|
||||
.list(),
|
||||
vec![
|
||||
json!({
|
||||
"name": "Updated address book",
|
||||
"description": "My updated personal address book",
|
||||
"sortOrder": 2,
|
||||
"isSubscribed": false,
|
||||
"isDefault": true,
|
||||
"id": addressbook_id,
|
||||
}),
|
||||
json!({
|
||||
"name": "Stalwart Address Book ([email protected])",
|
||||
"description": (),
|
||||
"sortOrder": 0,
|
||||
"isSubscribed": true,
|
||||
"isDefault": false,
|
||||
"id": default_addressbook_id,
|
||||
})
|
||||
]
|
||||
);
|
||||
|
||||
// Create a contact
|
||||
let _ = account
|
||||
.jmap_create(
|
||||
MethodObject::ContactCard,
|
||||
[json!({
|
||||
"addressBookIds": {
|
||||
&addressbook_id: true
|
||||
},
|
||||
"name": {
|
||||
"components": [
|
||||
{ "kind": "given", "value": "Joe" },
|
||||
{ "kind": "surname", "value": "Bloggs" }
|
||||
]
|
||||
},
|
||||
"emails": {
|
||||
"0": {
|
||||
"address": "[email protected]"
|
||||
}
|
||||
}
|
||||
})],
|
||||
Vec::<(&str, &str)>::new(),
|
||||
)
|
||||
.await
|
||||
.created(0)
|
||||
.id();
|
||||
|
||||
// Try destroying the address book (should fail)
|
||||
assert_eq!(
|
||||
account
|
||||
.jmap_destroy(
|
||||
MethodObject::AddressBook,
|
||||
[&addressbook_id],
|
||||
Vec::<(&str, &str)>::new(),
|
||||
)
|
||||
.await
|
||||
.not_destroyed(&addressbook_id)
|
||||
.typ(),
|
||||
"addressBookHasContents"
|
||||
);
|
||||
|
||||
// Destroy using force
|
||||
assert_eq!(
|
||||
account
|
||||
.jmap_destroy(
|
||||
MethodObject::AddressBook,
|
||||
[&addressbook_id],
|
||||
[("onDestroyRemoveContents", true)],
|
||||
)
|
||||
.await
|
||||
.destroyed()
|
||||
.collect::<Vec<_>>(),
|
||||
vec![&addressbook_id]
|
||||
);
|
||||
|
||||
// Destroy all mailboxes
|
||||
account.destroy_all_addressbooks().await;
|
||||
test.assert_is_empty().await;
|
||||
}
|
||||
Reference in New Issue
Block a user