mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-1547: Hook up remaining push notification sync handling (#848)
This commit is contained in:
committed by
Álison Fernandes
parent
d2ffd7bf01
commit
8489bd1476
@@ -64,10 +64,12 @@ import com.x8bit.bitwarden.data.auth.repository.util.toUserState
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.toUserStateJson
|
||||
import com.x8bit.bitwarden.data.auth.util.toSdkParams
|
||||
import com.x8bit.bitwarden.data.platform.base.FakeDispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.PushManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.FakeEnvironmentRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.data.platform.util.asFailure
|
||||
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockOrganization
|
||||
@@ -172,6 +174,13 @@ class AuthRepositoryTest {
|
||||
every { logout(any()) } just runs
|
||||
}
|
||||
|
||||
private val mutableLogoutFlow = bufferedMutableSharedFlow<Unit>()
|
||||
private val mutableSyncOrgKeysFlow = bufferedMutableSharedFlow<Unit>()
|
||||
private val pushManager: PushManager = mockk {
|
||||
every { logoutFlow } returns mutableLogoutFlow
|
||||
every { syncOrgKeysFlow } returns mutableSyncOrgKeysFlow
|
||||
}
|
||||
|
||||
private var elapsedRealtimeMillis = 123456789L
|
||||
|
||||
private val repository = AuthRepositoryImpl(
|
||||
@@ -190,6 +199,7 @@ class AuthRepositoryTest {
|
||||
vaultRepository = vaultRepository,
|
||||
userLogoutManager = userLogoutManager,
|
||||
dispatcherManager = dispatcherManager,
|
||||
pushManager = pushManager,
|
||||
elapsedRealtimeMillisProvider = { elapsedRealtimeMillis },
|
||||
)
|
||||
|
||||
@@ -2770,6 +2780,43 @@ class AuthRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `logOutFlow emission for action account should call logout on the UserLogoutManager and clear the user's in memory vault data`() {
|
||||
val userId = USER_ID_1
|
||||
fakeAuthDiskSource.userState = MULTI_USER_STATE
|
||||
|
||||
mutableLogoutFlow.tryEmit(Unit)
|
||||
|
||||
coVerify(exactly = 1) {
|
||||
userLogoutManager.logout(userId = userId)
|
||||
vaultRepository.clearUnlockedData()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `syncOrgKeysFlow emissions should refresh access token and sync`() {
|
||||
fakeAuthDiskSource.userState = SINGLE_USER_STATE_1
|
||||
coEvery {
|
||||
identityService.refreshTokenSynchronously(REFRESH_TOKEN)
|
||||
} returns REFRESH_TOKEN_RESPONSE_JSON.asSuccess()
|
||||
every {
|
||||
REFRESH_TOKEN_RESPONSE_JSON.toUserStateJson(
|
||||
userId = USER_ID_1,
|
||||
previousUserState = SINGLE_USER_STATE_1,
|
||||
)
|
||||
} returns SINGLE_USER_STATE_1
|
||||
|
||||
coEvery { vaultRepository.sync() } just runs
|
||||
|
||||
mutableSyncOrgKeysFlow.tryEmit(Unit)
|
||||
|
||||
coVerify(exactly = 1) {
|
||||
identityService.refreshTokenSynchronously(REFRESH_TOKEN)
|
||||
vaultRepository.sync()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val UNIQUE_APP_ID = "testUniqueAppId"
|
||||
private const val EMAIL = "test@bitwarden.com"
|
||||
|
||||
@@ -184,6 +184,8 @@ class PushManagerTest {
|
||||
assertEquals(
|
||||
SyncCipherUpsertData(
|
||||
cipherId = "aab5cdcc-f4a7-4e65-bf6d-5e0eab052321",
|
||||
organizationId = "6a41d965-ed95-4eae-98c3-5f1ec609c2c1",
|
||||
collectionIds = listOf(),
|
||||
revisionDate = ZonedDateTime.parse("2023-10-27T12:00:00.000Z"),
|
||||
isUpdate = false,
|
||||
),
|
||||
@@ -214,6 +216,8 @@ class PushManagerTest {
|
||||
assertEquals(
|
||||
SyncCipherUpsertData(
|
||||
cipherId = "aab5cdcc-f4a7-4e65-bf6d-5e0eab052321",
|
||||
organizationId = "6a41d965-ed95-4eae-98c3-5f1ec609c2c1",
|
||||
collectionIds = listOf(),
|
||||
revisionDate = ZonedDateTime.parse("2023-10-27T12:00:00.000Z"),
|
||||
isUpdate = true,
|
||||
),
|
||||
|
||||
+935
-79
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user