Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,73 @@ class AuthenticatorViewModelTest {
viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmTotpCode
}

@Test
fun `SMS MFA Code next step shows the SignInConfirmMfa screen`() = runTest {
coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false))
coEvery { authProvider.signIn(any(), any()) } returns Success(
mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE)
)

viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn))

viewModel.signIn("username", "password")
viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmMfa
}

@Test
fun `Custom Challenge next step shows the SignInConfirmCustomAuth screen`() = runTest {
coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false))
coEvery { authProvider.signIn(any(), any()) } returns Success(
mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE)
)

viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn))

viewModel.signIn("username", "password")
viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmCustomAuth
}

@Test
fun `New Password next step shows the SignInConfirmNewPassword screen`() = runTest {
coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false))
coEvery { authProvider.signIn(any(), any()) } returns Success(
mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_IN_WITH_NEW_PASSWORD)
)

viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn))

viewModel.signIn("username", "password")
viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmNewPassword
}

@Test
fun `Confirm SignUp next step, get error from resendSignUpCode, stays in SignIn screen`() = runTest {
coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false))
coEvery { authProvider.signIn(any(), any()) } returns Success(
mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_UP)
)
coEvery { authProvider.resendSignUpCode(any()) } returns AmplifyResult.Error(mockAuthException())

viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn))

viewModel.signIn("username", "password")
viewModel.currentStep shouldBe AuthenticatorStep.SignIn
}

@Test
fun `Confirm SignUp next step shows the SignUpConfirm screen`() = runTest {
coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false))
coEvery { authProvider.signIn(any(), any()) } returns Success(
mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_UP)
)
coEvery { authProvider.resendSignUpCode(any()) } returns Success(mockk())

viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn))

viewModel.signIn("username", "password")
viewModel.currentStep shouldBe AuthenticatorStep.SignUpConfirm
}

@Test
fun `MFA selection next step shows error if allowedMFATypes is null`() = runTest {
coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false))
Expand Down