Repo created
This commit is contained in:
parent
75dc487a7a
commit
39c29d175b
6317 changed files with 388324 additions and 2 deletions
15
feature/account/api/build.gradle.kts
Normal file
15
feature/account/api/build.gradle.kts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
plugins {
|
||||
id(ThunderbirdPlugins.Library.kmp)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "net.thunderbird.feature.account"
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
api(projects.core.architecture.api)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package net.thunderbird.feature.account
|
||||
|
||||
import net.thunderbird.core.architecture.model.Identifiable
|
||||
|
||||
/**
|
||||
* Interface representing an account by its unique identifier [AccountId].
|
||||
*/
|
||||
interface Account : Identifiable<Account>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package net.thunderbird.feature.account
|
||||
|
||||
import net.thunderbird.core.architecture.model.Id
|
||||
|
||||
/**
|
||||
* Represents a unique identifier for an [Account].
|
||||
*/
|
||||
typealias AccountId = Id<Account>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package net.thunderbird.feature.account
|
||||
|
||||
import net.thunderbird.core.architecture.model.BaseIdFactory
|
||||
|
||||
/**
|
||||
* Factory object for creating unique identifiers for [Account] instances.
|
||||
*/
|
||||
object AccountIdFactory : BaseIdFactory<Account>()
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package net.thunderbird.feature.account.profile
|
||||
|
||||
/**
|
||||
* Sealed interface representing the avatar of an account.
|
||||
*/
|
||||
sealed interface AccountAvatar {
|
||||
data class Monogram(
|
||||
val value: String,
|
||||
) : AccountAvatar
|
||||
|
||||
data class Image(
|
||||
val uri: String,
|
||||
) : AccountAvatar
|
||||
|
||||
data class Icon(
|
||||
val name: String,
|
||||
) : AccountAvatar
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package net.thunderbird.feature.account.profile
|
||||
|
||||
import net.thunderbird.feature.account.Account
|
||||
import net.thunderbird.feature.account.AccountId
|
||||
|
||||
/**
|
||||
* Data class representing an account profile.
|
||||
*
|
||||
* @property id The unique identifier of the account profile.
|
||||
* @property name The name of the account.
|
||||
* @property color The color associated with the account.
|
||||
* @property avatar The [AccountAvatar] representing the avatar of the account.
|
||||
*/
|
||||
data class AccountProfile(
|
||||
override val id: AccountId,
|
||||
val name: String,
|
||||
val color: Int,
|
||||
val avatar: AccountAvatar,
|
||||
) : Account
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package net.thunderbird.feature.account.profile
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import net.thunderbird.feature.account.AccountId
|
||||
|
||||
interface AccountProfileRepository {
|
||||
|
||||
fun getById(accountId: AccountId): Flow<AccountProfile?>
|
||||
|
||||
suspend fun update(accountProfile: AccountProfile)
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package net.thunderbird.feature.account
|
||||
|
||||
import assertk.Assert
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.hasMessage
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isInstanceOf
|
||||
import assertk.assertions.isNotEqualTo
|
||||
import kotlin.test.Test
|
||||
import kotlin.uuid.ExperimentalUuidApi
|
||||
import kotlin.uuid.Uuid
|
||||
|
||||
class AccountIdFactoryTest {
|
||||
|
||||
@Test
|
||||
fun `create should return AccountId with the same id`() {
|
||||
val id = "123e4567-e89b-12d3-a456-426614174000"
|
||||
|
||||
val result = AccountIdFactory.of(id)
|
||||
|
||||
assertThat(result.asRaw()).isEqualTo(id)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create should throw IllegalArgumentException when id is invalid`() {
|
||||
val id = "invalid"
|
||||
|
||||
val result = assertFailure {
|
||||
AccountIdFactory.of(id)
|
||||
}
|
||||
|
||||
result.hasMessage(
|
||||
"Expected either a 36-char string in the standard hex-and-dash UUID format or a 32-char " +
|
||||
"hexadecimal string, but was \"invalid\" of length 7",
|
||||
)
|
||||
result.isInstanceOf<IllegalArgumentException>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `new should return AccountId with a uuid`() {
|
||||
val result = AccountIdFactory.create()
|
||||
|
||||
assertThat(result.asRaw()).isUuid()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create should return AccountId with unique ids`() {
|
||||
val ids = List(10) { AccountIdFactory.create().asRaw() }
|
||||
|
||||
ids.forEachIndexed { index, id ->
|
||||
ids.drop(index + 1).forEach { otherId ->
|
||||
assertThat(id).isNotEqualTo(otherId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalUuidApi::class)
|
||||
private fun Assert<String>.isUuid() = given { actual ->
|
||||
Uuid.parse(actual)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue