diff --git a/feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/AccountEditModule.kt b/feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/AccountEditModule.kt index 1097d58ba..ca91aa4b0 100644 --- a/feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/AccountEditModule.kt +++ b/feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/AccountEditModule.kt @@ -23,7 +23,7 @@ val featureAccountEditModule = module { factory { LoadAccountState( - accountLoader = get(), + accountStateLoader = get(), accountStateRepository = get(), ) } diff --git a/feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountState.kt b/feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountState.kt index ea0676ca2..832fe6d93 100644 --- a/feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountState.kt +++ b/feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountState.kt @@ -2,13 +2,11 @@ package app.k9mail.feature.account.edit.domain.usecase import app.k9mail.feature.account.common.AccountCommonExternalContract import app.k9mail.feature.account.common.domain.AccountDomainContract -import app.k9mail.feature.account.common.domain.entity.Account import app.k9mail.feature.account.common.domain.entity.AccountState -import app.k9mail.feature.account.common.domain.entity.AuthorizationState import app.k9mail.feature.account.edit.domain.AccountEditDomainContract class LoadAccountState( - private val accountLoader: AccountCommonExternalContract.AccountLoader, + private val accountStateLoader: AccountCommonExternalContract.AccountStateLoader, private val accountStateRepository: AccountDomainContract.AccountStateRepository, ) : AccountEditDomainContract.UseCase.LoadAccountState { override suspend fun execute(accountUuid: String): AccountState { @@ -21,21 +19,11 @@ class LoadAccountState( } private suspend fun loadState(accountUuid: String): AccountState { - val account = accountLoader.loadAccount(accountUuid) - return if (account != null) { - val accountState = account.mapToAccountState() + val accountState = accountStateLoader.loadAccountState(accountUuid) + return if (accountState != null) { accountState } else { AccountState(uuid = accountUuid) }.also { accountStateRepository.setState(it) } } - - private fun Account.mapToAccountState() = AccountState( - uuid = uuid, - emailAddress = emailAddress, - incomingServerSettings = incomingServerSettings, - outgoingServerSettings = outgoingServerSettings, - authorizationState = AuthorizationState(authorizationState), - options = options, - ) } diff --git a/feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/AccountEditModuleKtTest.kt b/feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/AccountEditModuleKtTest.kt index 27ae9b175..41954b796 100644 --- a/feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/AccountEditModuleKtTest.kt +++ b/feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/AccountEditModuleKtTest.kt @@ -31,7 +31,7 @@ import org.robolectric.RuntimeEnvironment class AccountEditModuleKtTest : KoinTest { private val externalModule: Module = module { - single { Mockito.mock() } + single { Mockito.mock() } single { Mockito.mock() } single { TrustedSocketFactory { _, _, _, _ -> null } diff --git a/feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountStateTest.kt b/feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountStateTest.kt index b73953b5c..919982069 100644 --- a/feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountStateTest.kt +++ b/feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountStateTest.kt @@ -1,7 +1,6 @@ package app.k9mail.feature.account.edit.domain.usecase import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository -import app.k9mail.feature.account.common.domain.entity.Account import app.k9mail.feature.account.common.domain.entity.AccountOptions import app.k9mail.feature.account.common.domain.entity.AccountState import app.k9mail.feature.account.common.domain.entity.AuthorizationState @@ -10,6 +9,7 @@ import assertk.assertThat import assertk.assertions.isEqualTo import com.fsck.k9.mail.AuthType import com.fsck.k9.mail.ServerSettings +import kotlin.test.DefaultAsserter.fail import kotlinx.coroutines.test.runTest import org.junit.Test @@ -18,78 +18,39 @@ class LoadAccountStateTest { @Test fun `should load account state WHEN account in state repository has different UUID`() = runTest { val testSubject = LoadAccountState( - accountLoader = { accountUuid -> - Account( - uuid = accountUuid, - emailAddress = EMAIL_ADDRESS, - incomingServerSettings = INCOMING_SERVER_SETTINGS, - outgoingServerSettings = OUTGOING_SERVER_SETTINGS, - authorizationState = AUTHORIZATION_STATE, - options = OPTIONS, - ) + accountStateLoader = { _ -> + ACCOUNT_STATE }, - accountStateRepository = InMemoryAccountStateRepository(), + accountStateRepository = InMemoryAccountStateRepository( + state = ACCOUNT_STATE.copy(uuid = "differentUuid"), + ), ) val result = testSubject.execute(ACCOUNT_UUID) - assertThat(result).isEqualTo( - AccountState( - uuid = ACCOUNT_UUID, - emailAddress = EMAIL_ADDRESS, - incomingServerSettings = INCOMING_SERVER_SETTINGS, - outgoingServerSettings = OUTGOING_SERVER_SETTINGS, - authorizationState = AuthorizationState(AUTHORIZATION_STATE), - options = OPTIONS, - ), - ) + assertThat(result).isEqualTo(ACCOUNT_STATE) } @Test fun `should return account state WHEN account in state repository has same UUID`() = runTest { val testSubject = LoadAccountState( - accountLoader = { accountUuid -> - Account( - uuid = accountUuid, - emailAddress = EMAIL_ADDRESS, - incomingServerSettings = INCOMING_SERVER_SETTINGS, - outgoingServerSettings = OUTGOING_SERVER_SETTINGS, - authorizationState = AUTHORIZATION_STATE, - options = OPTIONS, - ) - }, - accountStateRepository = InMemoryAccountStateRepository().apply { - setState( - AccountState( - uuid = ACCOUNT_UUID, - emailAddress = EMAIL_ADDRESS, - incomingServerSettings = INCOMING_SERVER_SETTINGS, - outgoingServerSettings = OUTGOING_SERVER_SETTINGS, - authorizationState = AuthorizationState(AUTHORIZATION_STATE), - options = OPTIONS, - ), - ) + accountStateLoader = { _ -> + fail("AccountStateLoader should not be called in this test") }, + accountStateRepository = InMemoryAccountStateRepository( + state = ACCOUNT_STATE, + ), ) val result = testSubject.execute(ACCOUNT_UUID) - assertThat(result).isEqualTo( - AccountState( - uuid = ACCOUNT_UUID, - emailAddress = EMAIL_ADDRESS, - incomingServerSettings = INCOMING_SERVER_SETTINGS, - outgoingServerSettings = OUTGOING_SERVER_SETTINGS, - authorizationState = AuthorizationState(AUTHORIZATION_STATE), - options = OPTIONS, - ), - ) + assertThat(result).isEqualTo(ACCOUNT_STATE) } @Test fun `should return empty account state WHEN account loader returns null`() = runTest { val testSubject = LoadAccountState( - accountLoader = { null }, + accountStateLoader = { null }, accountStateRepository = InMemoryAccountStateRepository(), ) @@ -131,7 +92,7 @@ class LoadAccountStateTest { clientCertificateAlias = null, ) - const val AUTHORIZATION_STATE = "authorization state" + val AUTHORIZATION_STATE = AuthorizationState("authorization state") val OPTIONS = AccountOptions( accountName = "accountName", @@ -141,5 +102,14 @@ class LoadAccountStateTest { messageDisplayCount = 25, showNotification = true, ) + + val ACCOUNT_STATE = AccountState( + uuid = ACCOUNT_UUID, + emailAddress = EMAIL_ADDRESS, + incomingServerSettings = INCOMING_SERVER_SETTINGS, + outgoingServerSettings = OUTGOING_SERVER_SETTINGS, + authorizationState = AUTHORIZATION_STATE, + options = OPTIONS, + ) } }