Skip to content

Commit

Permalink
Change AccountState to use display and sync options
Browse files Browse the repository at this point in the history
  • Loading branch information
wmontwe committed Jan 10, 2024
1 parent 6036f18 commit a3a044e
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package app.k9mail.feature.preview.account

import app.k9mail.feature.account.common.AccountCommonExternalContract.AccountStateLoader
import app.k9mail.feature.account.common.domain.entity.Account
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
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.AccountSyncOptions
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountServerSettingsUpdater
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountUpdaterFailure
Expand Down Expand Up @@ -59,7 +62,24 @@ class InMemoryAccountStore(
incomingServerSettings = account.incomingServerSettings,
outgoingServerSettings = account.outgoingServerSettings,
authorizationState = account.authorizationState?.let { AuthorizationState(it) },
options = account.options,
displayOptions = mapToDisplayOptions(account.options),
syncOptions = mapToSyncOptions(account.options),
)
}

private fun mapToDisplayOptions(options: AccountOptions): AccountDisplayOptions {
return AccountDisplayOptions(
accountName = options.accountName,
displayName = options.displayName,
emailSignature = options.emailSignature,
)
}

private fun mapToSyncOptions(options: AccountOptions): AccountSyncOptions {
return AccountSyncOptions(
checkFrequencyInMinutes = options.checkFrequencyInMinutes,
messageDisplayCount = options.messageDisplayCount,
showNotification = options.showNotification,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.k9mail.feature.account.common.data

import app.k9mail.feature.account.common.domain.AccountDomainContract
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
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.AccountSyncOptions
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
Expand Down Expand Up @@ -43,10 +42,6 @@ class InMemoryAccountStateRepository(
state = state.copy(specialFolderSettings = specialFolderSettings)
}

override fun setOptions(options: AccountOptions) {
state = state.copy(options = options)
}

override fun setDisplayOptions(displayOptions: AccountDisplayOptions) {
state = state.copy(displayOptions = displayOptions)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.k9mail.feature.account.common.domain

import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
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.AccountSyncOptions
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
Expand All @@ -26,8 +25,6 @@ interface AccountDomainContract {

fun setSpecialFolderSettings(specialFolderSettings: SpecialFolderSettings)

fun setOptions(options: AccountOptions)

fun setDisplayOptions(displayOptions: AccountDisplayOptions)

fun setSyncOptions(syncOptions: AccountSyncOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ data class AccountState(
val outgoingServerSettings: ServerSettings? = null,
val authorizationState: AuthorizationState? = null,
val specialFolderSettings: SpecialFolderSettings? = null,
val options: AccountOptions? = null,
val displayOptions: AccountDisplayOptions? = null,
val syncOptions: AccountSyncOptions? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.k9mail.feature.account.common.ui.preview

import app.k9mail.feature.account.common.domain.AccountDomainContract
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
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.AccountSyncOptions
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
Expand Down Expand Up @@ -50,8 +49,6 @@ class PreviewAccountStateRepository : AccountDomainContract.AccountStateReposito

override fun setSpecialFolderSettings(specialFolderSettings: SpecialFolderSettings) = Unit

override fun setOptions(options: AccountOptions) = Unit

override fun setDisplayOptions(displayOptions: AccountDisplayOptions) = Unit

override fun setSyncOptions(syncOptions: AccountSyncOptions) = Unit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package app.k9mail.feature.account.common.data

import app.k9mail.feature.account.common.domain.entity.AccountOptions
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
import app.k9mail.feature.account.common.domain.entity.AccountState
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
import assertk.assertThat
import assertk.assertions.isEqualTo
Expand All @@ -25,7 +26,8 @@ class InMemoryAccountStateRepositoryTest {
incomingServerSettings = null,
outgoingServerSettings = null,
authorizationState = null,
options = null,
displayOptions = null,
syncOptions = null,
),
)
}
Expand All @@ -39,7 +41,8 @@ class InMemoryAccountStateRepositoryTest {
incomingServerSettings = INCOMING_SERVER_SETTINGS,
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
authorizationState = AuthorizationState("authorizationState"),
options = OPTIONS,
displayOptions = DISPLAY_OPTIONS,
syncOptions = SYNC_OPTIONS,
),
)
val newState = AccountState(
Expand All @@ -48,10 +51,12 @@ class InMemoryAccountStateRepositoryTest {
incomingServerSettings = INCOMING_SERVER_SETTINGS.copy(host = "imap2.example.org"),
outgoingServerSettings = OUTGOING_SERVER_SETTINGS.copy(host = "smtp2.example.org"),
authorizationState = AuthorizationState("authorizationState2"),
options = OPTIONS.copy(
displayOptions = DISPLAY_OPTIONS.copy(
accountName = "accountName2",
displayName = "displayName2",
emailSignature = "emailSignature2",
),
syncOptions = SYNC_OPTIONS.copy(
checkFrequencyInMinutes = 50,
messageDisplayCount = 60,
showNotification = false,
Expand Down Expand Up @@ -104,13 +109,21 @@ class InMemoryAccountStateRepositoryTest {
}

@Test
fun `should set options`() {
fun `should set display options`() {
val testSubject = InMemoryAccountStateRepository()

testSubject.setOptions(OPTIONS)
testSubject.setDisplayOptions(DISPLAY_OPTIONS)

assertThat(testSubject.getState().options)
.isEqualTo(OPTIONS)
assertThat(testSubject.getState().displayOptions).isEqualTo(DISPLAY_OPTIONS)
}

@Test
fun `should set sync options`() {
val testSubject = InMemoryAccountStateRepository()

testSubject.setSyncOptions(SYNC_OPTIONS)

assertThat(testSubject.getState().syncOptions).isEqualTo(SYNC_OPTIONS)
}

@Test
Expand All @@ -122,7 +135,8 @@ class InMemoryAccountStateRepositoryTest {
incomingServerSettings = INCOMING_SERVER_SETTINGS,
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
authorizationState = AuthorizationState("authorizationState"),
options = OPTIONS,
displayOptions = DISPLAY_OPTIONS,
syncOptions = SYNC_OPTIONS,
),
)

Expand All @@ -135,7 +149,8 @@ class InMemoryAccountStateRepositoryTest {
incomingServerSettings = null,
outgoingServerSettings = null,
authorizationState = null,
options = null,
displayOptions = null,
syncOptions = null,
),
)
}
Expand Down Expand Up @@ -163,10 +178,13 @@ class InMemoryAccountStateRepositoryTest {
null,
)

val OPTIONS = AccountOptions(
val DISPLAY_OPTIONS = AccountDisplayOptions(
accountName = "accountName",
displayName = "displayName",
emailSignature = "emailSignature",
)

val SYNC_OPTIONS = AccountSyncOptions(
checkFrequencyInMinutes = 10,
messageDisplayCount = 20,
showNotification = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class AccountStateTest {
prop(AccountState::incomingServerSettings).isNull()
prop(AccountState::outgoingServerSettings).isNull()
prop(AccountState::authorizationState).isNull()
prop(AccountState::options).isNull()
prop(AccountState::specialFolderSettings).isNull()
prop(AccountState::displayOptions).isNull()
prop(AccountState::syncOptions).isNull()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package app.k9mail.feature.account.edit.domain.usecase

import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
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.AccountSyncOptions
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
import app.k9mail.feature.account.common.domain.entity.MailConnectionSecurity
import assertk.assertFailure
Expand Down Expand Up @@ -77,13 +79,26 @@ class GetAccountStateTest {
showNotification = true,
)

val DISPLAY_OPTIONS = AccountDisplayOptions(
accountName = "accountName",
displayName = "displayName",
emailSignature = null,
)

val SYNC_OPTIONS = AccountSyncOptions(
checkFrequencyInMinutes = 15,
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,
displayOptions = DISPLAY_OPTIONS,
syncOptions = SYNC_OPTIONS,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package app.k9mail.feature.account.edit.domain.usecase

import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository
import app.k9mail.feature.account.common.domain.entity.AccountOptions
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
import app.k9mail.feature.account.common.domain.entity.AccountState
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
import app.k9mail.feature.account.common.domain.entity.MailConnectionSecurity
import assertk.assertFailure
Expand Down Expand Up @@ -72,10 +73,13 @@ class LoadAccountStateTest {

val AUTHORIZATION_STATE = AuthorizationState("authorization state")

val OPTIONS = AccountOptions(
val DISPLAY_OPTIONS = AccountDisplayOptions(
accountName = "accountName",
displayName = "displayName",
emailSignature = null,
)

val SYNC_OPTIONS = AccountSyncOptions(
checkFrequencyInMinutes = 15,
messageDisplayCount = 25,
showNotification = true,
Expand All @@ -87,7 +91,8 @@ class LoadAccountStateTest {
incomingServerSettings = INCOMING_SERVER_SETTINGS,
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
authorizationState = AUTHORIZATION_STATE,
options = OPTIONS,
displayOptions = DISPLAY_OPTIONS,
syncOptions = SYNC_OPTIONS,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package app.k9mail.feature.account.edit.domain.usecase

import app.k9mail.feature.account.common.domain.entity.AccountOptions
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
import app.k9mail.feature.account.common.domain.entity.AccountState
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
import app.k9mail.feature.account.common.domain.entity.MailConnectionSecurity
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountUpdaterFailure
Expand Down Expand Up @@ -143,10 +144,13 @@ class SaveServerSettingsTest {

val AUTHORIZATION_STATE = AuthorizationState("authorization state")

val OPTIONS = AccountOptions(
val DISPLAY_OPTIONS = AccountDisplayOptions(
accountName = "accountName",
displayName = "displayName",
emailSignature = null,
)

val SYNC_OPTIONS = AccountSyncOptions(
checkFrequencyInMinutes = 15,
messageDisplayCount = 25,
showNotification = true,
Expand All @@ -158,7 +162,8 @@ class SaveServerSettingsTest {
incomingServerSettings = INCOMING_SERVER_SETTINGS,
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
authorizationState = AUTHORIZATION_STATE,
options = OPTIONS,
displayOptions = DISPLAY_OPTIONS,
syncOptions = SYNC_OPTIONS,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ package app.k9mail.feature.account.setup.domain
import app.k9mail.autodiscovery.api.AutoDiscoveryResult
import app.k9mail.core.common.domain.usecase.validation.ValidationError
import app.k9mail.core.common.domain.usecase.validation.ValidationResult
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
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.SpecialFolderOptions
import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator.AccountCreatorResult
import com.fsck.k9.mail.ServerSettings

interface DomainContract {

Expand All @@ -18,15 +15,7 @@ interface DomainContract {
}

fun interface CreateAccount {
suspend fun execute(
emailAddress: String,
incomingServerSettings: ServerSettings,
outgoingServerSettings: ServerSettings,
authorizationState: String?,
specialFolderSettings: SpecialFolderSettings?,
options: AccountOptions,
displayOptions: AccountDisplayOptions,
): AccountCreatorResult
suspend fun execute(accountState: AccountState): AccountCreatorResult
}

fun interface ValidateEmailAddress {
Expand Down
Loading

0 comments on commit a3a044e

Please sign in to comment.