-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address book accounts: bind to accounts (again) (#1184)
* [WIP] Scope address book acounts to accounts again * [WIP] Tests * Fix LocalAddressBookStoreTest * Adapt AccountsCleanupWorker * Migration to assign accounts to address books (again) * Change account in address books on account rename
- Loading branch information
Showing
23 changed files
with
499 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,19 +47,24 @@ class LocalAddressBookStoreTest { | |
@SpyK | ||
lateinit var context: Context | ||
|
||
val account: Account = Account("[email protected]", "Mock Account Type") | ||
val account by lazy { Account("Test Account", context.getString(R.string.account_type)) } | ||
val addressBookAccount by lazy { Account("[email protected]", context.getString(R.string.account_type_address_book)) } | ||
|
||
val provider = mockk<ContentProviderClient>(relaxed = true) | ||
val addressBook: LocalAddressBook = mockk(relaxed = true) { | ||
every { account } answers { this@LocalAddressBookStoreTest.account } | ||
every { updateSyncFrameworkSettings() } just runs | ||
every { addressBookAccount } returns account | ||
every { addressBookAccount } answers { this@LocalAddressBookStoreTest.addressBookAccount } | ||
every { settings } returns LocalAddressBookStore.contactsProviderSettings | ||
} | ||
|
||
@Suppress("unused") // used by @InjectMockKs LocalAddressBookStore | ||
@RelaxedMockK | ||
lateinit var collectionRepository: DavCollectionRepository | ||
|
||
@Suppress("unused") // used by @InjectMockKs LocalAddressBookStore | ||
val localAddressBookFactory = mockk<LocalAddressBook.Factory> { | ||
every { create(account, provider) } returns addressBook | ||
every { create(any(), any(), provider) } returns addressBook | ||
} | ||
|
||
@Inject | ||
|
@@ -69,6 +74,7 @@ class LocalAddressBookStoreTest { | |
@RelaxedMockK | ||
lateinit var settingsManager: SettingsManager | ||
|
||
@Suppress("unused") // used by @InjectMockKs LocalAddressBookStore | ||
val serviceRepository = mockk<DavServiceRepository>(relaxed = true) { | ||
every { get(any<Long>()) } returns null | ||
every { get(200) } returns mockk<Service> { | ||
|
@@ -132,26 +138,28 @@ class LocalAddressBookStoreTest { | |
|
||
@Test | ||
fun test_create_createAccountReturnsNull() { | ||
val collection = mockk<Collection>(relaxed = true) { | ||
val collection = mockk<Collection>(relaxed = true) { | ||
every { serviceId } returns 200 | ||
every { id } returns 1 | ||
every { url } returns "https://example.com/addressbook/funnyfriends".toHttpUrl() | ||
} | ||
every { localAddressBookStore.createAccount(any(), any(), any()) } returns null | ||
every { localAddressBookStore.createAddressBookAccount(any(), any(), any(), any()) } returns null | ||
assertEquals(null, localAddressBookStore.create(provider, collection)) | ||
} | ||
|
||
@Test | ||
fun test_create_createAccountReturnsAccount() { | ||
val collection = mockk<Collection>(relaxed = true) { | ||
val collection = mockk<Collection>(relaxed = true) { | ||
every { serviceId } returns 200 | ||
every { id } returns 1 | ||
every { url } returns "https://example.com/addressbook/funnyfriends".toHttpUrl() | ||
} | ||
every { localAddressBookStore.createAccount(any(), any(), any()) } returns account | ||
every { localAddressBookStore.createAddressBookAccount(any(), any(), any(), any()) } returns addressBookAccount | ||
every { addressBook.readOnly } returns true | ||
val addrBook = localAddressBookStore.create(provider, collection)!! | ||
|
||
verify(exactly = 1) { addressBook.updateSyncFrameworkSettings() } | ||
assertEquals(account, addrBook.addressBookAccount) | ||
assertEquals(addressBookAccount, addrBook.addressBookAccount) | ||
assertEquals(LocalAddressBookStore.contactsProviderSettings, addrBook.settings) | ||
assertEquals(true, addrBook.readOnly) | ||
|
||
|
@@ -164,8 +172,8 @@ class LocalAddressBookStoreTest { | |
fun test_createAccount_succeeds() { | ||
mockkObject(SystemAccountUtils) | ||
every { SystemAccountUtils.createAccount(any(), any(), any()) } returns true | ||
val result: Account = localAddressBookStore.createAccount( | ||
"[email protected]", 42, "https://example.com/addressbook/funnyfriends" | ||
val result: Account = localAddressBookStore.createAddressBookAccount( | ||
account, "[email protected]", 42, "https://example.com/addressbook/funnyfriends" | ||
)!! | ||
verify(exactly = 1) { SystemAccountUtils.createAccount(any(), any(), any()) } | ||
assertEquals("[email protected]", result.name) | ||
|
@@ -174,14 +182,26 @@ class LocalAddressBookStoreTest { | |
|
||
|
||
@Test | ||
fun test_getAll_noCorrespondingCollection() { | ||
// account doesn't have an associated Collection in the database | ||
fun test_getAll_differentAccount() { | ||
val accountManager = AccountManager.get(context) | ||
mockkObject(accountManager) | ||
every { accountManager.getAccountsByType(any()) } returns arrayOf(addressBookAccount) | ||
every { accountManager.getUserData(addressBookAccount, LocalAddressBook.USER_DATA_ACCOUNT_NAME) } returns "Another Unrelated Account" | ||
every { accountManager.getUserData(addressBookAccount, LocalAddressBook.USER_DATA_ACCOUNT_TYPE) } returns account.type | ||
val result = localAddressBookStore.getAll(account, provider) | ||
assertTrue(result.isEmpty()) | ||
} | ||
|
||
@Test | ||
fun test_getAll_sameAccount() { | ||
val accountManager = AccountManager.get(context) | ||
mockkObject(accountManager) | ||
every { accountManager.getAccountsByType(any()) } returns arrayOf(account) | ||
every { accountManager.getAccountsByType(any()) } returns arrayOf(addressBookAccount) | ||
every { accountManager.getUserData(addressBookAccount, LocalAddressBook.USER_DATA_ACCOUNT_NAME) } returns account.name | ||
every { accountManager.getUserData(addressBookAccount, LocalAddressBook.USER_DATA_ACCOUNT_TYPE) } returns account.type | ||
val result = localAddressBookStore.getAll(account, provider) | ||
assertEquals(1, result.size) | ||
assertEquals(account, result.first().addressBookAccount) | ||
assertEquals(addressBookAccount, result.first().addressBookAccount) | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.