Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc725883 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

AM: Allow changing account type

- In old account manager, our app supported multiple types
  (Google, WebDAV, Yahoo, Murena). Adding this flexibility
  now ensures we can add new account types in future commits.
parent 67360f65
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -127,19 +127,19 @@ class AccountRepositoryTest {
        val existing = Account("Existing Account", accountType)
        am.addAccountExplicitly(existing, null, null)

        accountRepository.rename(account.name, existing.name)
        accountRepository.rename(accountType, account.name, existing.name,)
    }

    @Test
    fun testRename_locksAccountsCleanup() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        verify { AccountsCleanupWorker.lockAccountsCleanup() }
    }

    @Test
    fun testRename_renamesAccountInAndroid() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val accountsAfter = am.getAccountsByType(accountType)
        assertTrue(accountsAfter.any { it.name == newName })
@@ -147,14 +147,14 @@ class AccountRepositoryTest {

    @Test
    fun testRename_cancelsRunningSynchronizationOfOldAccount() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        coVerify { syncWorkerManager.cancelAllWork(account) }
    }

    @Test
    fun testRename_disablesPeriodicSyncsForOldAccount() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        for (dataType in SyncDataType.entries)
            coVerify(exactly = 1) {
@@ -164,48 +164,48 @@ class AccountRepositoryTest {

    @Test
    fun testRename_updatesAccountNameReferencesInDatabase() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        coVerify { serviceRepository.renameAccount(account.name, newName) }
    }

    @Test
    fun testRename_updatesAddressBooks() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val newAccount = accountRepository.fromName(newName)
        coVerify { localAddressBookStore.updateAccount(account, newAccount, any()) }
        val newAccount = accountRepository.fromName(newName, accountType)
        coVerify { localAddressBookStore.updateAccount(account, newAccount, any(), accountType) }
    }

    @Test
    fun testRename_updatesCalendarEvents() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val newAccount = accountRepository.fromName(newName)
        coVerify { localCalendarStore.updateAccount(account, newAccount, any()) }
        val newAccount = accountRepository.fromName(newName, accountType)
        coVerify { localCalendarStore.updateAccount(account, newAccount, any(), accountType) }
    }

    @Test
    fun testRename_updatesAccountNameOfLocalTasks() = runTest {
        val mockDataStore = mockk<LocalDataStore<*>>(relaxed = true)
        every { tasksAppManager.getDataStore() } returns mockDataStore
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val newAccount = accountRepository.fromName(newName)
        coVerify { mockDataStore.updateAccount(account, newAccount, any()) }
        val newAccount = accountRepository.fromName(newName, accountType)
        coVerify { mockDataStore.updateAccount(account, newAccount, any(), accountType) }
    }

    @Test
    fun testRename_updatesAutomaticSync() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val newAccount = accountRepository.fromName(newName)
        val newAccount = accountRepository.fromName(newName, accountType)
        coVerify { automaticSyncManager.updateAutomaticSync(newAccount) }
    }

    @Test
    fun testRename_releasesAccountsCleanupWorkerMutex() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        verify { AccountsCleanupWorker.lockAccountsCleanup() }
        coVerify { serviceRepository.renameAccount(account.name, newName) }
+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ class LocalAddressBookStoreTest {
        }

        mockkObject(localAddressBookStore)
        every { localAddressBookStore.createAddressBookAccount(any(), any(), any()) } returns null
        every { localAddressBookStore.createAddressBookAccount(any(), any(), any(), any()) } returns null

        assertEquals(null, localAddressBookStore.create(provider, collection))
    }
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ class LocalCalendarStoreTest {
        account = TestAccount.rename(account, "ChangedAccountName")

        // Update account name in local calendar
        localCalendarStore.updateAccount(oldAccount, account, provider)
        localCalendarStore.updateAccount(oldAccount, account, provider, account.type)

        // Verify [Calendar.OWNER_ACCOUNT] of local calendar was updated
        verifyOwnerAccountIs(provider, "ChangedAccountName")
+1 −1
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ class SyncerTest {
            throw NotImplementedError()
        }

        override fun updateAccount(oldAccount: Account, newAccount: Account, client: ContentProviderClient?) {
        override fun updateAccount(oldAccount: Account, newAccount: Account, client: ContentProviderClient?, accountType: String) {
            throw NotImplementedError()
        }

+2 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import foundation.e.accountmanager.utils.AccountHelper
import java.io.Writer
import javax.inject.Singleton

@@ -104,7 +105,7 @@ abstract class AppDatabase: RoomDatabase() {

                    // remove all accounts because they're unfortunately useless without database
                    val am = AccountManager.get(context)
                    for (account in am.getAccountsByType(context.getString(R.string.account_type)))
                    for (account in AccountHelper.getAllAccounts(am))
                        am.removeAccountExplicitly(account)
                }
            })
Loading