Skip to content

Commit

Permalink
Unit tests for after reAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime NATUREL committed Sep 27, 2022
1 parent dafa98e commit 68d9f67
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import io.mockk.runs
import io.mockk.slot
import io.mockk.unmockkAll
import io.mockk.verify
import io.mockk.verifyAll
import kotlinx.coroutines.flow.flowOf
import org.junit.After
import org.junit.Before
Expand All @@ -59,6 +60,7 @@ private const val A_SESSION_ID_1 = "session-id-1"
private const val A_SESSION_ID_2 = "session-id-2"
private const val AUTH_ERROR_MESSAGE = "auth-error-message"
private const val AN_ERROR_MESSAGE = "error-message"
private const val A_PASSWORD = "password"

class SessionOverviewViewModelTest {

Expand Down Expand Up @@ -319,6 +321,72 @@ class SessionOverviewViewModelTest {
.finish()
}

@Test
fun `given SSO auth has been done when handling ssoAuthDone action then corresponding method of pending auth handler is called`() {
// Given
val deviceFullInfo = mockk<DeviceFullInfo>()
every { deviceFullInfo.isCurrentDevice } returns false
every { getDeviceFullInfoUseCase.execute(A_SESSION_ID_1) } returns flowOf(deviceFullInfo)
val action = SessionOverviewAction.SsoAuthDone
givenCurrentSessionIsTrusted()
every { fakePendingAuthHandler.instance.ssoAuthDone() } just runs

// When
val viewModel = createViewModel()
val viewModelTest = viewModel.test()
viewModel.handle(action)

// Then
viewModelTest.finish()
verifyAll {
fakePendingAuthHandler.instance.ssoAuthDone()
}
}

@Test
fun `given password auth has been done when handling passwordAuthDone action then corresponding method of pending auth handler is called`() {
// Given
val deviceFullInfo = mockk<DeviceFullInfo>()
every { deviceFullInfo.isCurrentDevice } returns false
every { getDeviceFullInfoUseCase.execute(A_SESSION_ID_1) } returns flowOf(deviceFullInfo)
val action = SessionOverviewAction.PasswordAuthDone(password = A_PASSWORD)
givenCurrentSessionIsTrusted()
every { fakePendingAuthHandler.instance.passwordAuthDone(any()) } just runs

// When
val viewModel = createViewModel()
val viewModelTest = viewModel.test()
viewModel.handle(action)

// Then
viewModelTest.finish()
verifyAll {
fakePendingAuthHandler.instance.passwordAuthDone(A_PASSWORD)
}
}

@Test
fun `given reAuth has been cancelled when handling reAuthCancelled action then corresponding method of pending auth handler is called`() {
// Given
val deviceFullInfo = mockk<DeviceFullInfo>()
every { deviceFullInfo.isCurrentDevice } returns false
every { getDeviceFullInfoUseCase.execute(A_SESSION_ID_1) } returns flowOf(deviceFullInfo)
val action = SessionOverviewAction.ReAuthCancelled
givenCurrentSessionIsTrusted()
every { fakePendingAuthHandler.instance.reAuthCancelled() } just runs

// When
val viewModel = createViewModel()
val viewModelTest = viewModel.test()
viewModel.handle(action)

// Then
viewModelTest.finish()
verifyAll {
fakePendingAuthHandler.instance.reAuthCancelled()
}
}

private fun givenSignoutSuccess(deviceId: String) {
val interceptor = slot<UserInteractiveAuthInterceptor>()
val flowResponse = mockk<RegistrationFlowResponse>()
Expand Down

0 comments on commit 68d9f67

Please sign in to comment.