diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt index 44dc599765..5667b1cc57 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt @@ -101,7 +101,6 @@ class DevicesViewModel @AssistedInject constructor( } } - // TODO add unit tests private fun handleVerifyCurrentSessionAction() { viewModelScope.launch { val currentSessionCanBeVerified = checkIfCurrentSessionCanBeVerifiedUseCase.execute() diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt index d9a64c82ef..18796191af 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt @@ -145,6 +145,54 @@ class DevicesViewModelTest { coVerify { refreshDevicesOnCryptoDevicesChangeUseCase.execute() } } + @Test + fun `given current session can be verified when handling verify current session action then self verification event is posted`() { + // Given + givenVerificationService() + givenCurrentSessionCrossSigningInfo() + givenDeviceFullInfoList() + givenRefreshDevicesOnCryptoDevicesChange() + val verifyCurrentSessionAction = DevicesAction.VerifyCurrentSession + coEvery { checkIfCurrentSessionCanBeVerifiedUseCase.execute() } returns true + + // When + val viewModel = createViewModel() + val viewModelTest = viewModel.test() + viewModel.handle(verifyCurrentSessionAction) + + // Then + viewModelTest + .assertEvent { it is DevicesViewEvent.SelfVerification } + .finish() + coVerify { + checkIfCurrentSessionCanBeVerifiedUseCase.execute() + } + } + + @Test + fun `given current session cannot be verified when handling verify current session action then reset secrets event is posted`() { + // Given + givenVerificationService() + givenCurrentSessionCrossSigningInfo() + givenDeviceFullInfoList() + givenRefreshDevicesOnCryptoDevicesChange() + val verifyCurrentSessionAction = DevicesAction.VerifyCurrentSession + coEvery { checkIfCurrentSessionCanBeVerifiedUseCase.execute() } returns false + + // When + val viewModel = createViewModel() + val viewModelTest = viewModel.test() + viewModel.handle(verifyCurrentSessionAction) + + // Then + viewModelTest + .assertEvent { it is DevicesViewEvent.PromptResetSecrets } + .finish() + coVerify { + checkIfCurrentSessionCanBeVerifiedUseCase.execute() + } + } + private fun givenVerificationService(): FakeVerificationService { val fakeVerificationService = fakeActiveSessionHolder .fakeSession