Skip to content

Commit

Permalink
conflicts resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk committed Jun 28, 2024
1 parent 88fcbc9 commit a2ea5fd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 261 deletions.
4 changes: 0 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import scripts.Variants_gradle

/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
Expand Down Expand Up @@ -210,8 +208,6 @@ dependencies {
testRuntimeOnly(libs.junit5.vintage.engine)
testRuntimeOnly(libs.junit5.engine)
testImplementation(libs.androidx.paging.testing)
testImplementation(libs.robolectric)
testRuntimeOnly(libs.junit.vintage.engine)

// Acceptance/Functional tests dependencies
androidTestImplementation(libs.androidx.test.runner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import com.google.android.gms.location.Priority
import com.google.android.gms.tasks.CancellationTokenSource
import com.wire.android.AppJsonStyledLogger
import com.wire.android.util.extension.isGoogleServicesAvailable
<<<<<<< HEAD
import com.wire.kalium.logger.KaliumLogLevel
=======
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))
import kotlinx.coroutines.tasks.await
import javax.inject.Inject
import javax.inject.Singleton
Expand Down Expand Up @@ -58,16 +55,12 @@ class LocationPickerHelperFlavor @Inject constructor(
*/
@SuppressLint("MissingPermission")
private suspend fun getLocationWithGms(onSuccess: (GeoLocatedAddress) -> Unit, onError: () -> Unit) {
<<<<<<< HEAD
if (isLocationServicesEnabled()) {
if (locationPickerHelper.isLocationServicesEnabled()) {
AppJsonStyledLogger.log(
level = KaliumLogLevel.INFO,
leadingMessage = "GetLocation",
jsonStringKeyValues = mapOf("isUsingGms" to true)
)
=======
if (locationPickerHelper.isLocationServicesEnabled()) {
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))
val locationProvider = LocationServices.getFusedLocationProviderClient(context)
val currentLocation =
locationProvider.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, CancellationTokenSource().token).await()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,12 @@ import androidx.lifecycle.SavedStateHandle
import com.wire.android.config.CoroutineTestExtension
import com.wire.android.config.NavigationTestExtension
import com.wire.android.config.TestDispatcherProvider
<<<<<<< HEAD
=======
import com.wire.android.framework.TestConversation
import com.wire.android.framework.TestConversationDetails
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))
import com.wire.android.ui.home.conversations.details.participants.model.ConversationParticipantsData
import com.wire.android.ui.home.conversations.details.participants.usecase.ObserveParticipantsForConversationUseCase
import com.wire.android.ui.navArgs
import com.wire.android.ui.userprofile.other.OtherUserProfileScreenViewModelTest
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.NetworkFailure
import com.wire.kalium.logic.configuration.GuestRoomLinkStatus
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase
import com.wire.kalium.logic.feature.conversation.SyncConversationCodeUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationAccessRoleUseCase
Expand All @@ -47,133 +40,34 @@ import com.wire.kalium.logic.feature.conversation.guestroomlink.ObserveGuestRoom
import com.wire.kalium.logic.feature.conversation.guestroomlink.RevokeGuestRoomLinkResult
import com.wire.kalium.logic.feature.conversation.guestroomlink.RevokeGuestRoomLinkUseCase
import com.wire.kalium.logic.feature.user.guestroomlink.ObserveGuestRoomLinkFeatureFlagUseCase
<<<<<<< HEAD
=======
import com.wire.kalium.logic.functional.Either
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.impl.annotations.MockK
import kotlinx.coroutines.ExperimentalCoroutinesApi
<<<<<<< HEAD
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.internal.assertEquals
=======
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.internal.assertEquals
import org.junit.jupiter.api.BeforeEach
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@OptIn(ExperimentalCoroutinesApi::class)
<<<<<<< HEAD
@ExtendWith(CoroutineTestExtension::class)
@ExtendWith(NavigationTestExtension::class)
@ExtendWith(CoroutineTestExtension::class, NavigationTestExtension::class)
class EditGuestAccessViewModelTest {

val dispatcher = TestDispatcherProvider()

@Test
fun `given updateConversationAccessRole use case runs successfully, when trying to enable guest access, then enable guest access`() =
runTest {
runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withUpdateConversationAccessRoleResult(UpdateConversationAccessRoleUseCase.Result.Success)
.arrange()
advanceUntilIdle()
=======
@ExtendWith(CoroutineTestExtension::class, NavigationTestExtension::class)
class EditGuestAccessViewModelTest {

val dispatcher = TestDispatcherProvider()

@MockK
private lateinit var savedStateHandle: SavedStateHandle

@MockK
lateinit var updateConversationAccessRoleUseCase: UpdateConversationAccessRoleUseCase

@MockK
lateinit var observeConversationDetails: ObserveConversationDetailsUseCase

@MockK
lateinit var observeConversationMembers: ObserveParticipantsForConversationUseCase

@MockK
lateinit var generateGuestRoomLink: GenerateGuestRoomLinkUseCase

@MockK
lateinit var observeGuestRoomLink: ObserveGuestRoomLinkUseCase

@MockK
lateinit var revokeGuestRoomLink: RevokeGuestRoomLinkUseCase

@MockK
lateinit var observeGuestRoomLinkFeatureFlag: ObserveGuestRoomLinkFeatureFlagUseCase

@MockK
lateinit var canCreatePasswordProtectedLinks: CanCreatePasswordProtectedLinksUseCase

private lateinit var editGuestAccessViewModel: EditGuestAccessViewModel

private val conversationDetailsChannel = Channel<ObserveConversationDetailsUseCase.Result>(capacity = Channel.UNLIMITED)

@BeforeEach
fun setUp() {
MockKAnnotations.init(this, relaxUnitFun = true)
coEvery { savedStateHandle.navArgs<EditGuestAccessNavArgs>() } returns EditGuestAccessNavArgs(
conversationId = TestConversation.ID,
editGuessAccessParams = EditGuestAccessParams(
isGuestAccessAllowed = true,
isServicesAllowed = true,
isUpdatingGuestAccessAllowed = true
)
)
coEvery {
observeConversationDetails(any())
} returns conversationDetailsChannel.consumeAsFlow()
coEvery {
observeConversationMembers(any())
} returns flowOf(ConversationParticipantsData())
coEvery {
observeGuestRoomLink(any())
} returns flowOf(Either.Right(null))
coEvery {
observeGuestRoomLinkFeatureFlag()
} returns flowOf(GuestRoomLinkStatus(null, null))
coEvery {
canCreatePasswordProtectedLinks()
} returns true

editGuestAccessViewModel = EditGuestAccessViewModel(
observeConversationDetails = observeConversationDetails,
observeConversationMembers = observeConversationMembers,
updateConversationAccessRole = updateConversationAccessRoleUseCase,
generateGuestRoomLink = generateGuestRoomLink,
revokeGuestRoomLink = revokeGuestRoomLink,
observeGuestRoomLink = observeGuestRoomLink,
savedStateHandle = savedStateHandle,
observeGuestRoomLinkFeatureFlag = observeGuestRoomLinkFeatureFlag,
canCreatePasswordProtectedLinks = canCreatePasswordProtectedLinks,
dispatcher = dispatcher,
)
conversationDetailsChannel.trySend(ObserveConversationDetailsUseCase.Result.Success(TestConversationDetails.GROUP))
}

@Test
fun `given updateConversationAccessRole use case runs successfully, when trying to enable guest access, then enable guest access`() =
runTest(dispatcher.default()) {
editGuestAccessViewModel.editGuestAccessState = editGuestAccessViewModel.editGuestAccessState.copy(isGuestAccessAllowed = false)
coEvery {
updateConversationAccessRoleUseCase(any(), any(), any())
} returns UpdateConversationAccessRoleUseCase.Result.Success
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))

// when
editGuestAccessViewModel.updateGuestAccess(true)
Expand All @@ -185,7 +79,7 @@ class EditGuestAccessViewModelTest {

@Test
fun `given a failure when running updateConversationAccessRole, when trying to enable guest access, then do not enable guest access`() =
runTest {
runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withUpdateConversationAccessRoleResult(
Expand All @@ -203,7 +97,7 @@ class EditGuestAccessViewModelTest {

@Test
fun `given guest access is activated, when trying to disable guest access, then display dialog before disabling guest access`() =
runTest {
runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withUpdateConversationAccessRoleResult(UpdateConversationAccessRoleUseCase.Result.Success)
Expand All @@ -214,24 +108,17 @@ class EditGuestAccessViewModelTest {
editGuestAccessViewModel.updateGuestAccess(false)

// then
coVerify(inverse = true) { arrangement.updateConversationAccessRoleUseCase(any(), any(), any()) }
coVerify(inverse = true) { arrangement.updateConversationAccessRole(any(), any(), any()) }
assertEquals(true, editGuestAccessViewModel.editGuestAccessState.shouldShowGuestAccessChangeConfirmationDialog)
}

@Test
<<<<<<< HEAD
fun `given useCase runs with success, when_generating guest link, then invoke it once`() = runTest {
fun `given useCase runs with success, when_generating guest link, then invoke it once`() = runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withGenerateGuestRoomResult(GenerateGuestRoomLinkResult.Success)
.arrange()
advanceUntilIdle()
=======
fun `given useCase runs with success, when_generating guest link, then invoke it once`() = runTest(dispatcher.default()) {
coEvery {
generateGuestRoomLink.invoke(any(), any())
} returns GenerateGuestRoomLinkResult.Success
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))

// when
editGuestAccessViewModel.onRequestGuestRoomLink()
Expand All @@ -242,20 +129,13 @@ class EditGuestAccessViewModelTest {
}

@Test
<<<<<<< HEAD
fun `given useCase runs with failure, when generating guest link, then show dialog error`() = runTest {
fun `given useCase runs with failure, when generating guest link, then show dialog error`() = runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withGenerateGuestRoomResult(
GenerateGuestRoomLinkResult.Failure(NetworkFailure.NoNetworkConnection(RuntimeException("no network")))
).arrange()
advanceUntilIdle()
=======
fun `given useCase runs with failure, when generating guest link, then show dialog error`() = runTest(dispatcher.default()) {
coEvery {
generateGuestRoomLink(any(), any())
} returns GenerateGuestRoomLinkResult.Failure(NetworkFailure.NoNetworkConnection(null))
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))

// when
editGuestAccessViewModel.onRequestGuestRoomLink()
Expand All @@ -266,19 +146,12 @@ class EditGuestAccessViewModelTest {
}

@Test
<<<<<<< HEAD
fun `given useCase runs with success, when revoking guest link, then invoke it once`() = runTest {
fun `given useCase runs with success, when revoking guest link, then invoke it once`() = runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withRevokeGuestRoomLinkResult(RevokeGuestRoomLinkResult.Success)
.arrange()
advanceUntilIdle()
=======
fun `given useCase runs with success, when revoking guest link, then invoke it once`() = runTest(dispatcher.default()) {
coEvery {
revokeGuestRoomLink(any())
} returns RevokeGuestRoomLinkResult.Success
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))

// when
editGuestAccessViewModel.removeGuestLink()
Expand All @@ -289,19 +162,12 @@ class EditGuestAccessViewModelTest {
}

@Test
<<<<<<< HEAD
fun `given useCase runs with failure when revoking guest link then show dialog error`() = runTest {
fun `given useCase runs with failure when revoking guest link then show dialog error`() = runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withRevokeGuestRoomLinkResult(RevokeGuestRoomLinkResult.Failure(CoreFailure.MissingClientRegistration))
.arrange()
advanceUntilIdle()
=======
fun `given useCase runs with failure when revoking guest link then show dialog error`() = runTest(dispatcher.default()) {
coEvery {
revokeGuestRoomLink(any())
} returns RevokeGuestRoomLinkResult.Failure(CoreFailure.MissingClientRegistration)
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))

// when
editGuestAccessViewModel.removeGuestLink()
Expand All @@ -314,28 +180,12 @@ class EditGuestAccessViewModelTest {

@Test
fun `given updateConversationAccessRole use case runs successfully, when trying to disable guest access, then disable guest access`() =
<<<<<<< HEAD
runTest {
runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withUpdateConversationAccessRoleResult(UpdateConversationAccessRoleUseCase.Result.Success)
.arrange()
advanceUntilIdle()
=======
runTest(dispatcher.default()) {
editGuestAccessViewModel.editGuestAccessState = editGuestAccessViewModel.editGuestAccessState.copy(isGuestAccessAllowed = true)
coEvery {
updateConversationAccessRoleUseCase(any(), any(), any())
} coAnswers {
val accessRoles = secondArg<Set<Conversation.AccessRole>>()
val newConversationDetails = TestConversationDetails.GROUP.copy(
conversation = TestConversationDetails.GROUP.conversation.copy(accessRole = accessRoles.toList())
)
// mock emitting updated conversation details with new access roles
conversationDetailsChannel.send(ObserveConversationDetailsUseCase.Result.Success(newConversationDetails))
UpdateConversationAccessRoleUseCase.Result.Success
}
>>>>>>> 395395269 (fix: location sharing without gms when not moving [WPB-9724] (#3136))

// when
editGuestAccessViewModel.onGuestDialogConfirm()
Expand All @@ -347,7 +197,7 @@ class EditGuestAccessViewModelTest {

@Test
fun `given a failure running updateConversationAccessRole, when trying to disable guest access, then do not disable guest access`() =
runTest {
runTest(dispatcher.default()) {
// given
val (arrangement, editGuestAccessViewModel) = Arrangement()
.withUpdateConversationAccessRoleResult(
Expand All @@ -368,9 +218,6 @@ class EditGuestAccessViewModelTest {
@MockK
lateinit var savedStateHandle: SavedStateHandle

@MockK
lateinit var updateConversationAccessRoleUseCase: UpdateConversationAccessRoleUseCase

@MockK
lateinit var observeConversationDetails: ObserveConversationDetailsUseCase

Expand Down
Loading

0 comments on commit a2ea5fd

Please sign in to comment.