mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 19:05:56 +03:00
Adding unit tests for new action in DevicesViewModel
This commit is contained in:
parent
d826327773
commit
35db958279
2 changed files with 48 additions and 1 deletions
|
@ -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 a new issue