Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Nov 17, 2023
1 parent 196ccc4 commit 567af52
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ import io.mockative.given
import io.mockative.mock
import io.mockative.once
import io.mockative.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertFalse

@OptIn(ExperimentalCoroutinesApi::class)
class UserPropertyRepositoryTest {

@Test
Expand Down Expand Up @@ -93,7 +91,7 @@ class UserPropertyRepositoryTest {

assertFalse(result)
verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::isReadReceiptsEnabled)
.suspendFunction(arrangement.userConfigRepository::isReadReceiptsEnabled)
.wasInvoked(exactly = once)
}

Expand Down Expand Up @@ -123,14 +121,14 @@ class UserPropertyRepositoryTest {

fun withUpdateReadReceiptsLocallySuccess() = apply {
given(userConfigRepository)
.function(userConfigRepository::setReadReceiptsStatus)
.suspendFunction(userConfigRepository::setReadReceiptsStatus)
.whenInvokedWith(any())
.thenReturn(Either.Right(Unit))
}

fun withNullReadReceiptsStatus() = apply {
given(userConfigRepository)
.function(userConfigRepository::isReadReceiptsEnabled)
.suspendFunction(userConfigRepository::isReadReceiptsEnabled)
.whenInvoked()
.thenReturn(flowOf(Either.Left(StorageFailure.DataNotFound)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AppLockTeamFeatureConfigObserverTest {
val result = observer.invoke()

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::observeAppLockConfig)
.suspendFunction(arrangement.userConfigRepository::observeAppLockConfig)
.wasNotInvoked()
assertEquals(expectedAppLockValue, result.first())
}
Expand All @@ -73,7 +73,7 @@ class AppLockTeamFeatureConfigObserverTest {
val result = observer.invoke()

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::observeAppLockConfig)
.suspendFunction(arrangement.userConfigRepository::observeAppLockConfig)
.wasInvoked(exactly = once)
assertEquals(expectedAppLockValue, result.first())
}
Expand All @@ -93,7 +93,7 @@ class AppLockTeamFeatureConfigObserverTest {
val result = observer.invoke()

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::observeAppLockConfig)
.suspendFunction(arrangement.userConfigRepository::observeAppLockConfig)
.wasInvoked(exactly = once)
assertEquals(expectedAppLockValue, result.first())
}
Expand All @@ -108,14 +108,14 @@ class AppLockTeamFeatureConfigObserverTest {

fun withFailure(): Arrangement = apply {
given(userConfigRepository)
.function(userConfigRepository::observeAppLockConfig)
.suspendFunction(userConfigRepository::observeAppLockConfig)
.whenInvoked()
.thenReturn(flowOf(Either.Left(StorageFailure.DataNotFound)))
}

fun withSuccess(): Arrangement = apply {
given(userConfigRepository)
.function(userConfigRepository::observeAppLockConfig)
.suspendFunction(userConfigRepository::observeAppLockConfig)
.whenInvoked()
.thenReturn(flowOf(Either.Right(appLockTeamConfig)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ import io.mockative.given
import io.mockative.mock
import io.mockative.once
import io.mockative.verify
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

class MarkTeamAppLockStatusAsNotifiedUseCaseTest {

@Test
fun givenAppLockStatusChanged_whenMarkingAsNotified_thenSetAppLockAsNotified() {
fun givenAppLockStatusChanged_whenMarkingAsNotified_thenSetAppLockAsNotified() = runTest {
val (arrangement, useCase) = Arrangement()
.withSuccess()
.arrange()

useCase.invoke()

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::setTeamAppLockAsNotified)
.suspendFunction(arrangement.userConfigRepository::setTeamAppLockAsNotified)
.wasInvoked(once)
}

Expand All @@ -53,7 +54,7 @@ class MarkTeamAppLockStatusAsNotifiedUseCaseTest {

fun withSuccess() = apply {
given(userConfigRepository)
.function(userConfigRepository::setTeamAppLockAsNotified)
.suspendFunction(userConfigRepository::setTeamAppLockAsNotified)
.whenInvoked()
.thenReturn(Either.Right(Unit))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class IsEligibleToStartCallUseCaseTest {
.thenReturn(null)

given(userConfigRepository)
.function(userConfigRepository::isConferenceCallingEnabled)
.suspendFunction(userConfigRepository::isConferenceCallingEnabled)
.whenInvoked()
.thenReturn(Either.Left(StorageFailure.Generic(Throwable("error"))))

Expand All @@ -83,7 +83,7 @@ class IsEligibleToStartCallUseCaseTest {
.thenReturn(null)

given(userConfigRepository)
.function(userConfigRepository::isConferenceCallingEnabled)
.suspendFunction(userConfigRepository::isConferenceCallingEnabled)
.whenInvoked()
.thenReturn(Either.Left(StorageFailure.Generic(Throwable("error"))))

Expand All @@ -107,7 +107,7 @@ class IsEligibleToStartCallUseCaseTest {
.thenReturn(establishedCallConversationId)

given(userConfigRepository)
.function(userConfigRepository::isConferenceCallingEnabled)
.suspendFunction(userConfigRepository::isConferenceCallingEnabled)
.whenInvoked()
.thenReturn(Either.Left(StorageFailure.Generic(Throwable("error"))))

Expand All @@ -131,7 +131,7 @@ class IsEligibleToStartCallUseCaseTest {
.thenReturn(establishedCallConversationId)

given(userConfigRepository)
.function(userConfigRepository::isConferenceCallingEnabled)
.suspendFunction(userConfigRepository::isConferenceCallingEnabled)
.whenInvoked()
.thenReturn(Either.Right(true))

Expand All @@ -155,7 +155,7 @@ class IsEligibleToStartCallUseCaseTest {
.thenReturn(conversationId)

given(userConfigRepository)
.function(userConfigRepository::isConferenceCallingEnabled)
.suspendFunction(userConfigRepository::isConferenceCallingEnabled)
.whenInvoked()
.thenReturn(Either.Right(true))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.test_util.TestKaliumDispatcher
import com.wire.kalium.util.DateTimeUtil
import io.mockative.Mock
import io.mockative.any
import io.mockative.given
import io.mockative.mock
import io.mockative.verify
Expand Down Expand Up @@ -183,7 +182,7 @@ class ObserveE2EIRequiredUseCaseTest {
}

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::observeE2EINotificationTime)
.suspendFunction(arrangement.userConfigRepository::observeE2EINotificationTime)
.wasNotInvoked()
}

Expand All @@ -199,14 +198,14 @@ class ObserveE2EIRequiredUseCaseTest {

fun withMLSE2EISetting(setting: E2EISettings) = apply {
given(userConfigRepository)
.function(userConfigRepository::observeE2EISettings)
.suspendFunction(userConfigRepository::observeE2EISettings)
.whenInvoked()
.then { flowOf(Either.Right(setting)) }
}

fun withE2EINotificationTime(instant: Instant?) = apply {
given(userConfigRepository)
.function(userConfigRepository::observeE2EINotificationTime)
.suspendFunction(userConfigRepository::observeE2EINotificationTime)
.whenInvoked()
.then { flowOf(Either.Right(instant)) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ class ObserveOtherUserSecurityClassificationLabelUseCaseTest {

fun withGettingClassifiedDomainsDisabled() = apply {
given(userConfigRepository)
.function(userConfigRepository::getClassifiedDomainsStatus)
.suspendFunction(userConfigRepository::getClassifiedDomainsStatus)
.whenInvoked()
.thenReturn(flowOf(Either.Left(StorageFailure.DataNotFound)))
}

fun withGettingClassifiedDomains() = apply {
given(userConfigRepository)
.function(userConfigRepository::getClassifiedDomainsStatus)
.suspendFunction(userConfigRepository::getClassifiedDomainsStatus)
.whenInvoked()
.thenReturn(flowOf(Either.Right(ClassifiedDomainsStatus(true, listOf("wire.com", "bella.com")))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ class ObserveSecurityClassificationLabelUseCaseTest {

fun withGettingClassifiedDomainsDisabled() = apply {
given(userConfigRepository)
.function(userConfigRepository::getClassifiedDomainsStatus)
.suspendFunction(userConfigRepository::getClassifiedDomainsStatus)
.whenInvoked()
.thenReturn(emptyFlow())
}

fun withGettingClassifiedDomains(domains: List<String>) = apply {
given(userConfigRepository)
.function(userConfigRepository::getClassifiedDomainsStatus)
.suspendFunction(userConfigRepository::getClassifiedDomainsStatus)
.whenInvoked()
.thenReturn(flowOf(Either.Right(ClassifiedDomainsStatus(true, domains))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ package com.wire.kalium.logic.feature.featureConfig

import com.wire.kalium.logic.NetworkFailure
import com.wire.kalium.logic.configuration.FileSharingStatus
import com.wire.kalium.logic.configuration.GuestRoomLinkStatus
import com.wire.kalium.logic.configuration.UserConfigDataSource
import com.wire.kalium.logic.configuration.UserConfigRepository
import com.wire.kalium.logic.data.featureConfig.ConferenceCallingModel
import com.wire.kalium.logic.data.featureConfig.ConfigsStatusModel
import com.wire.kalium.logic.data.featureConfig.E2EIConfigModel
import com.wire.kalium.logic.data.featureConfig.E2EIModel
import com.wire.kalium.logic.data.featureConfig.FeatureConfigModel
import com.wire.kalium.logic.data.featureConfig.FeatureConfigRepository
import com.wire.kalium.logic.data.featureConfig.FeatureConfigTest
import com.wire.kalium.logic.data.featureConfig.E2EIConfigModel
import com.wire.kalium.logic.data.featureConfig.E2EIModel
import com.wire.kalium.logic.data.featureConfig.SelfDeletingMessagesConfigModel
import com.wire.kalium.logic.data.featureConfig.SelfDeletingMessagesModel
import com.wire.kalium.logic.data.featureConfig.Status
import com.wire.kalium.logic.data.message.SelfDeletionMapper.toTeamSelfDeleteTimer
import com.wire.kalium.logic.data.message.TeamSelfDeleteTimer
import com.wire.kalium.logic.feature.featureConfig.handler.AppLockConfigHandler
import com.wire.kalium.logic.feature.featureConfig.handler.ClassifiedDomainsConfigHandler
import com.wire.kalium.logic.feature.featureConfig.handler.ConferenceCallingConfigHandler
Expand All @@ -42,18 +43,18 @@ import com.wire.kalium.logic.feature.featureConfig.handler.MLSConfigHandler
import com.wire.kalium.logic.feature.featureConfig.handler.MLSMigrationConfigHandler
import com.wire.kalium.logic.feature.featureConfig.handler.SecondFactorPasswordChallengeConfigHandler
import com.wire.kalium.logic.feature.featureConfig.handler.SelfDeletingMessagesConfigHandler
import com.wire.kalium.logic.data.message.SelfDeletionMapper.toTeamSelfDeleteTimer
import com.wire.kalium.logic.data.message.TeamSelfDeleteTimer
import com.wire.kalium.logic.feature.user.UpdateSupportedProtocolsAndResolveOneOnOnesUseCase
import com.wire.kalium.logic.featureFlags.BuildFileRestrictionState
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.logic.framework.TestUser
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.test_util.TestNetworkException
import com.wire.kalium.logic.util.shouldSucceed
import com.wire.kalium.persistence.config.inMemoryUserConfigStorage
import com.wire.kalium.persistence.dao.SupportedProtocolEntity
import com.wire.kalium.persistence.dao.config.MLSConfigDAO
import com.wire.kalium.persistence.dao.config.UserConfigDAO
import com.wire.kalium.persistence.dao.config.model.IsFileSharingEnabledEntity
import com.wire.kalium.persistence.dao.config.model.IsGuestRoomLinkEnabledEntity
import io.mockative.Mock
import io.mockative.any
import io.mockative.classOf
Expand Down Expand Up @@ -281,8 +282,8 @@ class SyncFeatureConfigsUseCaseTest {
FeatureConfigTest.newModel(guestRoomLink = ConfigsStatusModel(Status.ENABLED))
)
.withGuestRoomLinkEnabledReturning(
GuestRoomLinkStatus(
isGuestRoomLinkEnabled = true,
IsGuestRoomLinkEnabledEntity(
status = true,
isStatusChanged = false
)
)
Expand All @@ -304,8 +305,8 @@ class SyncFeatureConfigsUseCaseTest {
FeatureConfigTest.newModel(guestRoomLink = ConfigsStatusModel(Status.DISABLED))
)
.withGuestRoomLinkEnabledReturning(
GuestRoomLinkStatus(
isGuestRoomLinkEnabled = false,
IsGuestRoomLinkEnabledEntity(
status = false,
isStatusChanged = false
)
)
Expand All @@ -327,8 +328,8 @@ class SyncFeatureConfigsUseCaseTest {
FeatureConfigTest.newModel(guestRoomLink = ConfigsStatusModel(Status.DISABLED))
)
.withGuestRoomLinkEnabledReturning(
GuestRoomLinkStatus(
isGuestRoomLinkEnabled = true,
IsGuestRoomLinkEnabledEntity(
status = true,
isStatusChanged = false
)
)
Expand All @@ -351,8 +352,8 @@ class SyncFeatureConfigsUseCaseTest {
FeatureConfigTest.newModel(guestRoomLink = ConfigsStatusModel(Status.ENABLED))
)
.withGuestRoomLinkEnabledReturning(
GuestRoomLinkStatus(
isGuestRoomLinkEnabled = false,
IsGuestRoomLinkEnabledEntity(
status = false,
isStatusChanged = false
)
)
Expand Down Expand Up @@ -627,16 +628,17 @@ class SyncFeatureConfigsUseCaseTest {

private class Arrangement {

private val inMemoryStorage = inMemoryUserConfigStorage()

var kaliumConfigs = KaliumConfigs()

@Mock
val userConfigDAO: UserConfigDAO = mock(UserConfigDAO::class)

@Mock
val mlsConfigDAO: MLSConfigDAO = mock(MLSConfigDAO::class)

var userConfigRepository: UserConfigRepository = UserConfigDataSource(
inMemoryStorage,
userConfigDAO,
mlsConfigDAO,
kaliumConfigs
)
private set
Expand All @@ -656,8 +658,8 @@ class SyncFeatureConfigsUseCaseTest {
// isStatusChanged = false
// )
withGuestRoomLinkEnabledReturning(
GuestRoomLinkStatus(
isGuestRoomLinkEnabled = true,
IsGuestRoomLinkEnabledEntity(
status = true,
isStatusChanged = false
)
)
Expand All @@ -668,8 +670,8 @@ class SyncFeatureConfigsUseCaseTest {
) = apply {
kaliumConfigs = kaliumConfigs.copy(fileRestrictionState = state)
userConfigRepository = UserConfigDataSource(
inMemoryStorage,
userConfigDAO,
mlsConfigDAO,
kaliumConfigs
)
}
Expand All @@ -688,16 +690,17 @@ class SyncFeatureConfigsUseCaseTest {
status: Boolean,
isStatusChanged: Boolean?
) = apply {
userConfigRepository.setFileSharingStatus(
status, isStatusChanged
)
given(userConfigDAO)
.suspendFunction(userConfigDAO::isFileSharingEnabled)
.whenInvoked()
.then { IsFileSharingEnabledEntity(status, isStatusChanged) }
}

fun withGuestRoomLinkEnabledReturning(guestRoomLinkStatus: GuestRoomLinkStatus) = apply {
inMemoryStorage.persistGuestRoomLinkFeatureFlag(
guestRoomLinkStatus.isGuestRoomLinkEnabled ?: false,
guestRoomLinkStatus.isStatusChanged
)
fun withGuestRoomLinkEnabledReturning(guestRoomLinkStatus: IsGuestRoomLinkEnabledEntity) = apply {
given(userConfigDAO)
.suspendFunction(userConfigDAO::isGuestRoomLinkEnabled)
.whenInvoked()
.then { guestRoomLinkStatus }
}

fun withGetTeamSettingsSelfDeletionStatusSuccessful() = apply {
Expand Down
Loading

0 comments on commit 567af52

Please sign in to comment.