From 802256875a21d178c76ecaf9730d79189bdb0f09 Mon Sep 17 00:00:00 2001 From: Patrick Honkonen Date: Wed, 7 Jan 2026 15:24:17 -0500 Subject: [PATCH] Refactor MigrateToMyItemsViewModel dependencies and sync logic Objective: Remove unused dependencies and simplify the vault sync invocation during ViewModel initialization. Behavioral changes: The vault sync is now triggered using `sync` instead of `syncForResult` and is no longer wrapped in a `viewModelScope` coroutine, simplifying the initialization flow. Specific changes: - Modify `MigrateToMyItemsViewModel` to remove the unused `VaultMigrationManager` dependency. - Update `MigrateToMyItemsViewModel` constructor to accept `VaultSyncManager` as a parameter rather than a property. - Update the `init` block in `MigrateToMyItemsViewModel` to call `vaultSyncManager.sync(forced = true)` directly without a coroutine wrapper. - Update `MigrateToMyItemsViewModelTest` to remove the mock and constructor usage of `VaultMigrationManager`. --- .../migratetomyitems/MigrateToMyItemsViewModel.kt | 12 ++++-------- .../MigrateToMyItemsViewModelTest.kt | 3 --- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/migratetomyitems/MigrateToMyItemsViewModel.kt b/app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/migratetomyitems/MigrateToMyItemsViewModel.kt index 7245a41101..272e31763f 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/migratetomyitems/MigrateToMyItemsViewModel.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/migratetomyitems/MigrateToMyItemsViewModel.kt @@ -9,7 +9,6 @@ import com.bitwarden.ui.util.Text import com.bitwarden.ui.util.asText import com.x8bit.bitwarden.data.platform.manager.event.OrganizationEventManager import com.x8bit.bitwarden.data.platform.manager.model.OrganizationEvent -import com.x8bit.bitwarden.data.vault.manager.VaultMigrationManager import com.x8bit.bitwarden.data.vault.manager.VaultSyncManager import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.delay @@ -28,8 +27,7 @@ private const val KEY_STATE = "state" @HiltViewModel class MigrateToMyItemsViewModel @Inject constructor( private val organizationEventManager: OrganizationEventManager, - val vaultMigrationManager: VaultMigrationManager, - val vaultSyncManager: VaultSyncManager, + vaultSyncManager: VaultSyncManager, savedStateHandle: SavedStateHandle, ) : BaseViewModel( initialState = savedStateHandle[KEY_STATE] ?: run { @@ -46,11 +44,9 @@ class MigrateToMyItemsViewModel @Inject constructor( stateFlow .onEach { savedStateHandle[KEY_STATE] = it } .launchIn(viewModelScope) - viewModelScope.launch { - // We need to ensure we have the most recent data. No need to do anything - // RootNavViewModel will take care of navigating if needed - vaultSyncManager.syncForResult(forced = true) - } + // We need to ensure we have the most recent data. No need to do anything + // RootNavViewModel will take care of navigating if needed + vaultSyncManager.sync(forced = true) } override fun handleAction(action: MigrateToMyItemsAction) { diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/migratetomyitems/MigrateToMyItemsViewModelTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/migratetomyitems/MigrateToMyItemsViewModelTest.kt index 046701e472..0b83cbfdd5 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/migratetomyitems/MigrateToMyItemsViewModelTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/migratetomyitems/MigrateToMyItemsViewModelTest.kt @@ -7,7 +7,6 @@ import com.bitwarden.ui.platform.resource.BitwardenString import com.bitwarden.ui.util.asText import com.x8bit.bitwarden.data.platform.manager.event.OrganizationEventManager import com.x8bit.bitwarden.data.platform.manager.model.OrganizationEvent -import com.x8bit.bitwarden.data.vault.manager.VaultMigrationManager import com.x8bit.bitwarden.data.vault.manager.VaultSyncManager import io.mockk.every import io.mockk.just @@ -28,7 +27,6 @@ class MigrateToMyItemsViewModelTest : BaseViewModelTest() { private val mockOrganizationEventManager: OrganizationEventManager = mockk { every { trackEvent(any()) } just runs } - private val mockVaultMigrationManager: VaultMigrationManager = mockk(relaxed = true) private val mockVaultSyncManager: VaultSyncManager = mockk(relaxed = true) @BeforeEach @@ -180,7 +178,6 @@ class MigrateToMyItemsViewModelTest : BaseViewModelTest() { ) return MigrateToMyItemsViewModel( organizationEventManager = mockOrganizationEventManager, - vaultMigrationManager = mockVaultMigrationManager, vaultSyncManager = mockVaultSyncManager, savedStateHandle = savedStateHandle, )