mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Adding unit tests for new action in DevicesViewModel
This commit is contained in:
parent
d826327773
commit
35db958279
@ -101,7 +101,6 @@ class DevicesViewModel @AssistedInject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO add unit tests
|
||||
private fun handleVerifyCurrentSessionAction() {
|
||||
viewModelScope.launch {
|
||||
val currentSessionCanBeVerified = checkIfCurrentSessionCanBeVerifiedUseCase.execute()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user