Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/jira-lint-and-link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ jobs:
steps:
- name: Get version name from source
id: version
env:
REPO: ${{ github.repository }}
BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
VERSION=$(curl -s https://raw.githubusercontent.com/${{ github.repository }}/${{ github.head_ref || github.ref_name }}/build-logic/plugins/src/main/kotlin/AndroidCoordinates.kt | grep 'const val versionName' | sed -E 's/.*"([^"]+)".*/\1/')
echo "version_name=$VERSION" >> $GITHUB_OUTPUT
VERSION=$(curl -s "https://raw.githubusercontent.com/${REPO}/${BRANCH}/build-logic/plugins/src/main/kotlin/AndroidCoordinates.kt" | grep 'const val versionName' | sed -E 's/.*"([^"]+)".*/\1/')
echo "version_name=$VERSION" >> "$GITHUB_OUTPUT"

add-jira-description:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.wire.kalium.logic.feature.service.ObserveAllServicesUseCase
import com.wire.kalium.logic.feature.service.ObserveIsServiceMemberUseCase
import com.wire.kalium.logic.feature.service.SearchServicesByNameUseCase
import com.wire.kalium.logic.feature.service.ServiceScope
import com.wire.kalium.logic.feature.service.SyncServicesUseCase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -58,6 +59,11 @@ class ServicesModule {
fun provideObserveAllServicesUseCase(serviceScope: ServiceScope): ObserveAllServicesUseCase =
serviceScope.observeAllServices

@ViewModelScoped
@Provides
fun provideSyncServicesUseCase(serviceScope: ServiceScope): SyncServicesUseCase =
serviceScope.syncServices

@ViewModelScoped
@Provides
fun provideSearchServicesByNameUseCase(serviceScope: ServiceScope): SearchServicesByNameUseCase =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.wire.kalium.logic.feature.featureConfig.AppsAllowedResult
import com.wire.kalium.logic.feature.featureConfig.ObserveIsAppsAllowedForUsageUseCase
import com.wire.kalium.logic.feature.service.ObserveAllServicesUseCase
import com.wire.kalium.logic.feature.service.SearchServicesByNameUseCase
import com.wire.kalium.logic.feature.service.SyncServicesUseCase
import com.wire.kalium.logic.feature.user.ObserveSelfUserUseCase
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
Expand All @@ -55,6 +56,7 @@ import kotlinx.coroutines.launch
class SearchAppsViewModel @AssistedInject constructor(
@Assisted val protocolInfo: Conversation.ProtocolInfo?,
private val getAllServices: ObserveAllServicesUseCase,
private val syncServices: SyncServicesUseCase,
private val getAllApps: ObserveAllAppsUseCase,
private val contactMapper: ContactMapper,
private val searchServicesByName: SearchServicesByNameUseCase,
Expand All @@ -63,6 +65,7 @@ class SearchAppsViewModel @AssistedInject constructor(
private val observeSelfUser: ObserveSelfUserUseCase
) : ViewModel() {
private val searchQueryTextFlow = MutableStateFlow(String.EMPTY)
private var servicesSynced = false
var state: SearchServicesState by mutableStateOf(SearchServicesState(isLoading = true))
private set

Expand Down Expand Up @@ -113,6 +116,10 @@ class SearchAppsViewModel @AssistedInject constructor(
val result = if (showNewApps) {
if (query.isEmpty()) getAllApps() else searchAppsByName(query)
} else {
if (!servicesSynced) {
servicesSynced = true
launch { syncServices() }
Comment thread
saleniuk marked this conversation as resolved.
}
if (query.isEmpty()) getAllServices() else searchServicesByName(query)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import com.wire.kalium.logic.feature.app.SearchAppsByNameUseCase
import com.wire.kalium.logic.feature.featureConfig.AppsAllowedProtocol
import com.wire.kalium.logic.feature.featureConfig.AppsAllowedResult
import com.wire.kalium.logic.feature.featureConfig.ObserveIsAppsAllowedForUsageUseCase
import com.wire.kalium.common.error.NetworkFailure
import com.wire.kalium.logic.feature.service.ObserveAllServicesUseCase
import com.wire.kalium.logic.feature.service.SearchServicesByNameUseCase
import com.wire.kalium.logic.feature.service.SyncServicesUseCase
import com.wire.kalium.logic.feature.user.ObserveSelfUserUseCase
import io.mockk.MockKAnnotations
import io.mockk.coEvery
Expand Down Expand Up @@ -266,6 +268,66 @@ class SearchAppsViewModelTest {
assertEquals(1, viewModel.state.result.size)
}

@Test
fun `given services branch is used across multiple searches, when init view model, then syncServices is called exactly once`() =
runTest {
// given
val query = "Service Name"
val (arrangement, viewModel) = Arrangement()
.withAppsAllowedForUsage(AppsAllowedResult.Enabled(AppsAllowedProtocol.PROTEUS))
.withGetAllServices(listOf(SERVICE_DETAILS))
.withSearchServicesByName(query, listOf(SERVICE_DETAILS))
.arrange(protocolInfo = null)

// when
advanceUntilIdle()
viewModel.searchQueryChanged(query)
advanceUntilIdle()
viewModel.searchQueryChanged(String.EMPTY)
advanceUntilIdle()

// then
coVerify(exactly = 1) {
arrangement.syncServices()
}
}

@Test
fun `given apps branch is used, when init view model, then syncServices is never called`() =
runTest {
// given
val (arrangement, _) = Arrangement()
.withAppsAllowedForUsage(AppsAllowedResult.Enabled(AppsAllowedProtocol.MLS))
.withGetAllApps(listOf(SERVICE_DETAILS))
.arrange(protocolInfo = null)

// when
advanceUntilIdle()

// then
coVerify(exactly = 0) {
arrangement.syncServices()
}
}

@Test
fun `given syncServices fails, when services branch is used, then observed services are still emitted`() =
runTest {
// given
val (_, viewModel) = Arrangement()
.withAppsAllowedForUsage(AppsAllowedResult.Enabled(AppsAllowedProtocol.PROTEUS))
.withGetAllServices(listOf(SERVICE_DETAILS, SERVICE_DETAILS2))
.withSyncServicesFailing()
.arrange(protocolInfo = null)

// when
advanceUntilIdle()

// then
assertEquals(2, viewModel.state.result.size)
assertFalse(viewModel.state.isLoading)
}

@Test
fun `given Apps feature flag is PROTEUS enabled, when searching for Apps by name, then load searched Services`() =
runTest {
Expand Down Expand Up @@ -340,6 +402,9 @@ class SearchAppsViewModelTest {
@MockK
lateinit var getAllServices: ObserveAllServicesUseCase

@MockK
lateinit var syncServices: SyncServicesUseCase

@MockK
lateinit var getAllApps: ObserveAllAppsUseCase

Expand All @@ -362,6 +427,7 @@ class SearchAppsViewModelTest {
MockKAnnotations.init(this, relaxUnitFun = true)

coEvery { getAllServices() } returns flowOf(emptyList())
coEvery { syncServices() } returns SyncServicesUseCase.Result.Success
coEvery { getAllApps() } returns flowOf(emptyList())
coEvery { searchServicesByName(any()) } returns flowOf(emptyList())
coEvery { searchAppsByName(any()) } returns flowOf(emptyList())
Expand All @@ -375,6 +441,7 @@ class SearchAppsViewModelTest {
fun arrange(protocolInfo: Conversation.ProtocolInfo?) = this to SearchAppsViewModel(
protocolInfo = protocolInfo,
getAllServices = getAllServices,
syncServices = syncServices,
getAllApps = getAllApps,
contactMapper = contactMapper,
searchServicesByName = searchServicesByName,
Expand Down Expand Up @@ -402,5 +469,9 @@ class SearchAppsViewModelTest {
fun withSearchServicesByName(query: String, result: List<ServiceDetails>) = apply {
coEvery { searchServicesByName(query) } returns flowOf(result)
}

fun withSyncServicesFailing() = apply {
coEvery { syncServices() } returns SyncServicesUseCase.Result.Failure(NetworkFailure.NoNetworkConnection(cause = null))
}
}
}
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 21 files
+1 −1 .github/actions/setup-java-gradle/action.yml
+1 −1 buildSrc/src/main/kotlin/com/wire/kalium/plugins/CommonJvmConfig.kt
+1 −1 buildSrc/src/main/kotlin/com/wire/kalium/plugins/Multiplatform.kt
+1 −1 gradle/libs.versions.toml
+9 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt
+75 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/MigrateConversationToMLSUseCase.kt
+14 −10 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrator.kt
+10 −34 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/service/ObserveAllServicesUseCase.kt
+5 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/service/ServiceScope.kt
+55 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/service/SyncServicesUseCase.kt
+1 −1 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/asset/AssetRepositoryTest.kt
+171 −0 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/MigrateConversationToMLSUseCaseTest.kt
+1 −26 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/service/ObserveAllServicesUseCaseTest.kt
+108 −0 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/service/SyncServicesUseCaseTest.kt
+3 −3 test/android-benchmarks/build.gradle.kts
+2 −2 test/benchmarks/build.gradle.kts
+1 −1 tools/monkeys/docker/Dockerfile
+1 −1 tools/protobuf-codegen/build.gradle.kts
+2 −2 tools/testservice/Dockerfile
+2 −2 tools/testservice/Jenkinsfile
+2 −2 tools/testservice/build.gradle.kts
Loading