One branding module (types::brand!) supplies the name to every protocol greeting, the HTTP realm, the startup banner, Received headers, the user agent, the IMAP ID response and calendar PRODIDs. The sign-in and calendar pages take ihasmail's palette and font and the INBUXA logo, and calendar emails embed the INBUXA lockup. Default calendar and address book names follow. Protocol identifiers (urn:stalwart:jmap, vnd.stalwart Sieve extensions) and upstream copyright notices are unchanged.
217 lines
6.0 KiB
Rust
217 lines
6.0 KiB
Rust
/*
|
|
* 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": "INBUXA 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": "INBUXA 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;
|
|
}
|