Adding unit tests about multi signout action for devices view model
This commit is contained in:
parent
880ee4058c
commit
a3df90ae3e
|
@ -78,7 +78,7 @@ class DevicesViewModelTest {
|
||||||
private val fakeSignoutSessionsUseCase = FakeSignoutSessionsUseCase()
|
private val fakeSignoutSessionsUseCase = FakeSignoutSessionsUseCase()
|
||||||
private val fakeInterceptSignoutFlowResponseUseCase = mockk<InterceptSignoutFlowResponseUseCase>()
|
private val fakeInterceptSignoutFlowResponseUseCase = mockk<InterceptSignoutFlowResponseUseCase>()
|
||||||
private val fakePendingAuthHandler = FakePendingAuthHandler()
|
private val fakePendingAuthHandler = FakePendingAuthHandler()
|
||||||
private val refreshDevicesUseCase = mockk<RefreshDevicesUseCase>(relaxUnitFun = true)
|
private val fakeRefreshDevicesUseCase = mockk<RefreshDevicesUseCase>(relaxUnitFun = true)
|
||||||
|
|
||||||
private fun createViewModel(): DevicesViewModel {
|
private fun createViewModel(): DevicesViewModel {
|
||||||
return DevicesViewModel(
|
return DevicesViewModel(
|
||||||
|
@ -92,7 +92,7 @@ class DevicesViewModelTest {
|
||||||
signoutSessionsUseCase = fakeSignoutSessionsUseCase.instance,
|
signoutSessionsUseCase = fakeSignoutSessionsUseCase.instance,
|
||||||
interceptSignoutFlowResponseUseCase = fakeInterceptSignoutFlowResponseUseCase,
|
interceptSignoutFlowResponseUseCase = fakeInterceptSignoutFlowResponseUseCase,
|
||||||
pendingAuthHandler = fakePendingAuthHandler.instance,
|
pendingAuthHandler = fakePendingAuthHandler.instance,
|
||||||
refreshDevicesUseCase = refreshDevicesUseCase,
|
refreshDevicesUseCase = fakeRefreshDevicesUseCase,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,12 +231,38 @@ class DevicesViewModelTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given no reAuth is needed when handling multiSignout other sessions action then signout process is performed`() {
|
||||||
|
// Given
|
||||||
|
val expectedViewState = givenInitialViewState(deviceId1 = A_DEVICE_ID_1, deviceId2 = A_CURRENT_DEVICE_ID)
|
||||||
|
// signout all devices except the current device
|
||||||
|
fakeSignoutSessionsUseCase.givenSignoutSuccess(listOf(A_DEVICE_ID_1), fakeInterceptSignoutFlowResponseUseCase)
|
||||||
|
|
||||||
|
// When
|
||||||
|
val viewModel = createViewModel()
|
||||||
|
val viewModelTest = viewModel.test()
|
||||||
|
viewModel.handle(DevicesAction.MultiSignoutOtherSessions)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
viewModelTest
|
||||||
|
.assertStatesChanges(
|
||||||
|
expectedViewState,
|
||||||
|
{ copy(isLoading = true) },
|
||||||
|
{ copy(isLoading = false) }
|
||||||
|
)
|
||||||
|
.assertEvent { it is DevicesViewEvent.SignoutSuccess }
|
||||||
|
.finish()
|
||||||
|
verify {
|
||||||
|
fakeRefreshDevicesUseCase.execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given server error during multiSignout when handling multiSignout other sessions action then signout process is performed`() {
|
fun `given server error during multiSignout when handling multiSignout other sessions action then signout process is performed`() {
|
||||||
// Given
|
// Given
|
||||||
val serverError = Failure.OtherServerError(errorBody = "", httpCode = HttpsURLConnection.HTTP_UNAUTHORIZED)
|
val serverError = Failure.OtherServerError(errorBody = "", httpCode = HttpsURLConnection.HTTP_UNAUTHORIZED)
|
||||||
fakeSignoutSessionsUseCase.givenSignoutError(listOf(A_DEVICE_ID_1, A_DEVICE_ID_2), serverError)
|
fakeSignoutSessionsUseCase.givenSignoutError(listOf(A_DEVICE_ID_1, A_DEVICE_ID_2), serverError)
|
||||||
val expectedViewState = givenInitialViewState()
|
val expectedViewState = givenInitialViewState(deviceId1 = A_DEVICE_ID_1, deviceId2 = A_DEVICE_ID_2)
|
||||||
fakeStringProvider.given(R.string.authentication_error, AUTH_ERROR_MESSAGE)
|
fakeStringProvider.given(R.string.authentication_error, AUTH_ERROR_MESSAGE)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
@ -260,7 +286,7 @@ class DevicesViewModelTest {
|
||||||
// Given
|
// Given
|
||||||
val error = Exception()
|
val error = Exception()
|
||||||
fakeSignoutSessionsUseCase.givenSignoutError(listOf(A_DEVICE_ID_1, A_DEVICE_ID_2), error)
|
fakeSignoutSessionsUseCase.givenSignoutError(listOf(A_DEVICE_ID_1, A_DEVICE_ID_2), error)
|
||||||
val expectedViewState = givenInitialViewState()
|
val expectedViewState = givenInitialViewState(deviceId1 = A_DEVICE_ID_1, deviceId2 = A_DEVICE_ID_2)
|
||||||
fakeStringProvider.given(R.string.matrix_error, AN_ERROR_MESSAGE)
|
fakeStringProvider.given(R.string.matrix_error, AN_ERROR_MESSAGE)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
@ -395,9 +421,9 @@ class DevicesViewModelTest {
|
||||||
return deviceFullInfoList
|
return deviceFullInfoList
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun givenInitialViewState(): DevicesViewState {
|
private fun givenInitialViewState(deviceId1: String, deviceId2: String): DevicesViewState {
|
||||||
val currentSessionCrossSigningInfo = givenCurrentSessionCrossSigningInfo()
|
val currentSessionCrossSigningInfo = givenCurrentSessionCrossSigningInfo()
|
||||||
val deviceFullInfoList = givenDeviceFullInfoList(deviceId1 = A_DEVICE_ID_1, deviceId2 = A_DEVICE_ID_2)
|
val deviceFullInfoList = givenDeviceFullInfoList(deviceId1, deviceId2)
|
||||||
return DevicesViewState(
|
return DevicesViewState(
|
||||||
currentSessionCrossSigningInfo = currentSessionCrossSigningInfo,
|
currentSessionCrossSigningInfo = currentSessionCrossSigningInfo,
|
||||||
devices = Success(deviceFullInfoList),
|
devices = Success(deviceFullInfoList),
|
||||||
|
|
Loading…
Reference in New Issue