Skip to content

Commit

Permalink
chore: version bump & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
y9vad9 committed Dec 24, 2023
1 parent 2c7d226 commit 7c2b8e1
Show file tree
Hide file tree
Showing 67 changed files with 218 additions and 298 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
plugins {
id("multiplatform-library-convention")
id("org.jetbrains.compose")
id("com.android.library")
}

kotlin {
jvmToolchain(19)
}

android {
compileSdk = 34

defaultConfig {
namespace = "io.timemates.app.ui"
}

compileOptions {
targetCompatibility = JavaVersion.VERSION_19
sourceCompatibility = JavaVersion.VERSION_19
buildFeatures {
compose = true
}
}

dependencies {
commonMainImplementation(compose.ui)
commonMainImplementation(compose.foundation)
commonMainApi(compose.ui)
commonMainApi(compose.foundation)
commonMainImplementation(compose.runtime)
commonMainImplementation(compose.material3)
commonMainImplementation(compose.materialIconsExtended)
commonMainImplementation(compose.uiTooling)
commonMainApi(compose.material3)
commonMainApi(compose.materialIconsExtended)
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ CREATE TABLE Authorization (
refreshHashExpiresAt INTEGER NOT NULL,
generationTime INTEGER NOT NULL,
metadataClientName TEXT,
metadataClientVersion TEXT,
metadataClientVersion REAL NOT NULL,
userId INTEGER NOT NULL,
metadataClientIpAddress TEXT,
isCurrent INTEGER AS kotlin.Boolean NOT NULL
);
Expand Down Expand Up @@ -43,5 +44,5 @@ FROM Authorization
WHERE isCurrent;

add:
INSERT INTO Authorization (id, accessHashValue, accessHashExpiresAt, refreshHashValue, refreshHashExpiresAt, generationTime, metadataClientName, metadataClientVersion, metadataClientIpAddress, isCurrent)
VALUES (:id, :accessHashValue, :accessHashExpiresAt, :refreshHashValue, :refreshHashExpiresAt, :generationTime, :metadataClientName, :metadataClientVersion, :metadataClientIpAddress, TRUE);
INSERT INTO Authorization (id, accessHashValue, accessHashExpiresAt, refreshHashValue, refreshHashExpiresAt, generationTime, metadataClientName, metadataClientVersion, metadataClientIpAddress, userId, isCurrent)
VALUES (:id, :accessHashValue, :accessHashExpiresAt, :refreshHashValue, :refreshHashExpiresAt, :generationTime, :metadataClientName, :metadataClientVersion, :metadataClientIpAddress, :userId, TRUE);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import io.timemates.sdk.authorization.email.requests.ConfirmAuthorizationRequest
import io.timemates.sdk.authorization.email.types.value.VerificationHash
import io.timemates.sdk.authorization.sessions.AuthorizedSessionsApi
import io.timemates.sdk.authorization.sessions.types.Authorization
import io.timemates.sdk.authorization.sessions.types.value.ApplicationName
import io.timemates.sdk.authorization.sessions.types.value.ClientIpAddress
import io.timemates.sdk.authorization.sessions.types.value.ClientVersion
import io.timemates.sdk.authorization.sessions.types.value.ConfirmationCode
import io.timemates.sdk.common.constructor.createOrThrow
import io.timemates.sdk.common.exceptions.UnsupportedException
import io.timemates.sdk.users.profile.types.value.EmailAddress
import io.timemates.sdk.users.profile.types.value.UserDescription
Expand All @@ -31,10 +35,10 @@ class AuthorizationsRepository(
}

override suspend fun authorize(emailAddress: EmailAddress): Result<VerificationHash> {
return emailAuthApi.authorize(emailAddress)
return emailAuthApi.authorize(emailAddress, Authorization.Metadata(appName, appVersion, ClientIpAddress.createOrThrow("UNDEFINED")))
}

override suspend fun confirm(verificationHash: VerificationHash, code: ConfirmationCode): Result<ConfirmAuthorizationRequest.Response> {
override suspend fun confirm(verificationHash: VerificationHash, code: ConfirmationCode): Result<ConfirmAuthorizationRequest.Result> {
return emailAuthApi.confirm(verificationHash, code)
}

Expand All @@ -53,14 +57,18 @@ class AuthorizationsRepository(
refreshHashValue = refreshHash!!.value.string,
refreshHashExpiresAt = refreshHash!!.expiresAt.toEpochMilliseconds(),
generationTime = generationTime.toEpochMilliseconds(),
metadataClientName = metadata?.clientName?.string,
metadataClientName = metadata?.applicationName?.string,
metadataClientIpAddress = metadata?.clientIpAddress?.string,
metadataClientVersion = metadata?.clientVersion?.string
metadataClientVersion = metadata?.clientVersion!!.double,
userId = userId.long,
)
}
}

}


}
}

private val appName = ApplicationName.createOrThrow("TimeMates App")
private val appVersion = ClientVersion.createOrThrow(1.0)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.timemates.app.authorization.data
import io.timemates.sdk.authorization.sessions.types.Authorization
import io.timemates.sdk.authorization.types.value.HashValue
import io.timemates.sdk.common.constructor.createOrThrow
import io.timemates.sdk.users.profile.types.value.UserId
import kotlinx.datetime.Instant
import io.timemates.app.authorization.data.database.Authorization as DbAuthorization

Expand All @@ -18,6 +19,7 @@ class DbAuthorizationMapper {
Instant.fromEpochMilliseconds(accessHashExpiresAt),
),
generationTime = Instant.fromEpochMilliseconds(generationTime),
userId = UserId.createOrThrow(userId),
metadata = null, // TODO when metadata will be implemented on server
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.timemates.app.authorization.dependencies
import app.cash.sqldelight.db.SqlDriver
import io.timemates.app.authorization.data.DatabaseAccessHashProvider
import io.timemates.app.authorization.data.DbAuthorizationMapper
import io.timemates.app.authorization.data.database.AccountDatabaseQueries
import io.timemates.app.authorization.repositories.AuthorizationsRepository
import io.timemates.data.database.TimeMatesAuthorizations
import io.timemates.sdk.authorization.email.EmailAuthorizationApi
Expand All @@ -13,7 +12,6 @@ import io.timemates.sdk.common.providers.AccessHashProvider
import org.koin.core.annotation.Factory
import org.koin.core.annotation.Module
import org.koin.core.annotation.Named
import org.koin.core.annotation.Singleton
import io.timemates.app.authorization.data.AuthorizationsRepository as AuthorizationsRepositoryImpl

@Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConfirmAuthorizationModule {

@Factory
fun confirmAuthorizationUseCase(
authorizationsRepository: AuthorizationsRepository
authorizationsRepository: AuthorizationsRepository,
): ConfirmEmailAuthorizationUseCase = ConfirmEmailAuthorizationUseCase(authorizationsRepository)

@Factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface AuthorizationsRepository {
* @return A [Result] indicating the success or failure of the confirmation request,
* with the response from the confirmation as the successful result.
*/
suspend fun confirm(verificationHash: VerificationHash, code: ConfirmationCode): Result<ConfirmAuthorizationRequest.Response>
suspend fun confirm(verificationHash: VerificationHash, code: ConfirmationCode): Result<ConfirmAuthorizationRequest.Result>

/**
* Creates a new user account with the given verification hash, user name, and user description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import io.timemates.sdk.common.exceptions.InvalidArgumentException
import io.timemates.sdk.common.exceptions.TooManyRequestsException

class ConfirmEmailAuthorizationUseCase(
private val authorizations: AuthorizationsRepository
private val authorizations: AuthorizationsRepository,
) {
suspend fun execute(
verificationHash: VerificationHash,
code: ConfirmationCode
code: ConfirmationCode,
): Result {
return authorizations.confirm(verificationHash, code)
.map { result -> Result.Success(result.authorization, result.isNewAccount) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AuthorizeByEmailUseCaseTest {
fun `execute with TooManyRequestsException should return TooManyRequests`() {
// GIVEN
val emailAddress = EmailAddress.createOrThrow("test@example.com")
val exception = TooManyRequestsException("Too many requests")
val exception = TooManyRequestsException("Too many requests", cause = null)
coEvery { authorizationsRepository.authorize(emailAddress) } returns Result.failure(exception)

// WHEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConfirmEmailAuthorizationUseCaseTest {
val isNewAccount = false
coEvery { authorizationsRepository.confirm(verificationHash, confirmationCode) } returns
Result.success(
ConfirmAuthorizationRequest.Response(
ConfirmAuthorizationRequest.Result(
isNewAccount, authorization,
)
)
Expand All @@ -47,7 +47,7 @@ class ConfirmEmailAuthorizationUseCaseTest {
// GIVEN
val verificationHash = VerificationHash.createOrThrow(Random.nextString(VerificationHash.SIZE))
val confirmationCode = ConfirmationCode.createOrThrow("123456")
val exception = TooManyRequestsException("Too many requests")
val exception = TooManyRequestsException("Too many requests", cause = null)
coEvery { authorizationsRepository.confirm(verificationHash, confirmationCode) } returns Result.failure(exception)

// WHEN
Expand Down
3 changes: 0 additions & 3 deletions feature/authorization/presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ dependencies {
commonMainImplementation(projects.styleSystem)

commonTestImplementation(projects.foundation.random)

commonMainImplementation(libs.moko.resources.compose)
commonMainImplementation(libs.moko.resources)
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import dev.icerock.moko.resources.compose.fontFamilyResource
import dev.icerock.moko.resources.compose.painterResource
import io.github.skeptick.libres.compose.painterResource
import io.timemates.app.authorization.ui.afterstart.mvi.AfterStartStateMachine
import io.timemates.app.authorization.ui.afterstart.mvi.AfterStartStateMachine.Event
import io.timemates.app.foundation.mvi.EmptyState
Expand All @@ -40,7 +39,7 @@ fun AfterStartScreen(
navigateToConfirmation: (String) -> Unit,
navigateToStart: () -> Unit,
) {
val painter: Painter = painterResource(Resources.images.confirm_authorization_info_image)
val painter: Painter = Resources.image.confirm_authorization_info_image.painterResource()

LaunchedEffect(Unit) {
stateMachine.effects.consumeEach { effect ->
Expand Down Expand Up @@ -90,7 +89,6 @@ fun AfterStartScreen(
Text(
text = LocalStrings.current.confirmation,
modifier = Modifier,
fontFamily = fontFamilyResource(Resources.fonts.Inter.black),
style = MaterialTheme.typography.titleLarge,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package io.timemates.app.authorization.ui.afterstart.mvi

import io.timemates.app.authorization.ui.afterstart.mvi.AfterStartStateMachine.Effect
import io.timemates.app.authorization.ui.afterstart.mvi.AfterStartStateMachine.Event
import io.timemates.app.foundation.mvi.StateMachine
import io.timemates.app.foundation.mvi.EmptyState
import io.timemates.app.foundation.mvi.StateMachine
import io.timemates.app.foundation.mvi.UiEffect
import io.timemates.app.foundation.mvi.UiEvent
import io.timemates.sdk.authorization.email.types.value.VerificationHash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ConfirmAuthorizationMiddleware : Middleware<State, Effect> {
Effect.TooManyAttempts,
Effect.AttemptIsFailed,
is Effect.NavigateToCreateAccount,
is Effect.NavigateToHome
is Effect.NavigateToHome,
-> store.state.value.copy(isLoading = false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import dev.icerock.moko.resources.compose.fontFamilyResource
import dev.icerock.moko.resources.compose.painterResource
import io.github.skeptick.libres.compose.painterResource
import io.timemates.app.authorization.ui.initial_authorization.mvi.InitialAuthorizationStateMachine.Effect
import io.timemates.app.authorization.ui.initial_authorization.mvi.InitialAuthorizationStateMachine.Event
import io.timemates.app.foundation.mvi.EmptyState
Expand All @@ -35,10 +34,10 @@ fun InitialAuthorizationScreen(
stateMachine: StateMachine<EmptyState, Event, Effect>,
navigateToStartAuthorization: () -> Unit,
) {
val painter: Painter = painterResource(Resources.images.initial_screen_image)
val painter: Painter = Resources.image.initial_screen_image.painterResource()

LaunchedEffect(Unit) {
stateMachine.effects.consumeEach { effect ->
stateMachine.effects.consumeEach { effect ->
when (effect) {
is Effect.NavigateToStart ->
navigateToStartAuthorization()
Expand Down Expand Up @@ -68,7 +67,6 @@ fun InitialAuthorizationScreen(
Text(
text = LocalStrings.current.welcome,
modifier = Modifier,
fontFamily = fontFamilyResource(Resources.fonts.Inter.black),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.timemates.app.foundation.mvi.UiEvent

class InitialAuthorizationStateMachine(
reducer: InitialAuthorizationReducer,
): StateMachine<EmptyState, Event, Effect>(
) : StateMachine<EmptyState, Event, Effect>(
reducer = reducer,
middlewares = emptyList(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import dev.icerock.moko.resources.compose.fontFamilyResource
import dev.icerock.moko.resources.compose.painterResource
import io.github.skeptick.libres.compose.painterResource
import io.timemates.app.authorization.ui.new_account_info.mvi.NewAccountInfoStateMachine.Effect
import io.timemates.app.authorization.ui.new_account_info.mvi.NewAccountInfoStateMachine.Event
import io.timemates.app.foundation.mvi.EmptyState
Expand All @@ -40,7 +39,7 @@ fun NewAccountInfoScreen(
navigateToConfigure: (String) -> Unit,
navigateToStart: () -> Unit,
) {
val painter: Painter = painterResource(Resources.images.new_account_info_image)
val painter: Painter = Resources.image.new_account_info_image.painterResource()

LaunchedEffect(Unit) {
stateMachine.effects.consumeEach { effect ->
Expand Down Expand Up @@ -90,7 +89,6 @@ fun NewAccountInfoScreen(
Text(
text = LocalStrings.current.almostDone,
modifier = Modifier,
fontFamily = fontFamilyResource(Resources.fonts.Inter.black),
style = MaterialTheme.typography.titleLarge,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package io.timemates.app.authorization.ui.new_account_info.mvi

import io.timemates.app.authorization.ui.new_account_info.mvi.NewAccountInfoStateMachine.Effect
import io.timemates.app.authorization.ui.new_account_info.mvi.NewAccountInfoStateMachine.Event
import io.timemates.app.foundation.mvi.StateMachine
import io.timemates.app.foundation.mvi.EmptyState
import io.timemates.app.foundation.mvi.StateMachine
import io.timemates.app.foundation.mvi.UiEffect
import io.timemates.app.foundation.mvi.UiEvent
import io.timemates.sdk.authorization.email.types.value.VerificationHash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class StartAuthorizationReducer(

private fun authorizeWithEmail(
email: String,
sendEffect: (Effect) -> Unit
sendEffect: (Effect) -> Unit,
) {
coroutineScope.launch {
when (val result = authorizeByEmail.execute(EmailAddress.createOrThrow(email))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ class ConfigureAccountMiddlewareTest {

// WHEN
effects.map { effect -> effect to middleware.onEffect(effect, stateStore) }
// THEN
.forEach { (effect, state) ->
assert(!state.isLoading) {
"${effect::class.simpleName} effect does not change loading status to false."
}
// THEN
.forEach { (effect, state) ->
assert(!state.isLoading) {
"${effect::class.simpleName} effect does not change loading status to false."
}
}
}

@Test
fun `effects not produced by network operations should not remove loading status`() {
// GIVEN
val effects = listOf(
ConfigureAccountStateMachine.Effect.NavigateToStart,
ConfigureAccountStateMachine.Effect.NavigateToHomePage(authorization)
ConfigureAccountStateMachine.Effect.NavigateToStart,
ConfigureAccountStateMachine.Effect.NavigateToHomePage(authorization)
)
every { stateStore.state } returns MutableStateFlow(ConfigureAccountStateMachine.State(isLoading = true))

// WHEN
effects.map { effect -> effect to middleware.onEffect(effect, stateStore) }
// THEN
.forEach { (effect, state) ->
assert(state.isLoading) {
"${effect::class.simpleName} effect changes loading status regardless it shouldn't"
}
// THEN
.forEach { (effect, state) ->
assert(state.isLoading) {
"${effect::class.simpleName} effect changes loading status regardless it shouldn't"
}
}
}
}
Loading

0 comments on commit 7c2b8e1

Please sign in to comment.