diff --git a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt index bf2ce8c6..e77cec91 100644 --- a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt +++ b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt @@ -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))