-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(2fa): login button disabled after verifiction backpress [WPB-3590] (
- Loading branch information
1 parent
46a57b7
commit bb0ab62
Showing
2 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,8 @@ import io.mockk.impl.annotations.MockK | |
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.StandardTestDispatcher | ||
import kotlinx.coroutines.test.TestScope | ||
import kotlinx.coroutines.test.advanceUntilIdle | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.datetime.Instant | ||
|
@@ -126,6 +128,10 @@ class LoginEmailViewModelTest { | |
|
||
private val userId: QualifiedID = QualifiedID("userId", "domain") | ||
|
||
private val dispatcherProvider = TestDispatcherProvider(StandardTestDispatcher()) | ||
|
||
private fun runTest(test: suspend TestScope.() -> Unit) = runTest(dispatcherProvider.main(), testBody = test) | ||
|
||
@BeforeEach | ||
fun setup() { | ||
MockKAnnotations.init(this) | ||
|
@@ -152,7 +158,7 @@ class LoginEmailViewModelTest { | |
authServerConfigProvider, | ||
userDataStoreProvider, | ||
coreLogic, | ||
TestDispatcherProvider() | ||
dispatcherProvider | ||
) | ||
} | ||
|
||
|
@@ -333,6 +339,21 @@ class LoginEmailViewModelTest { | |
coVerify(exactly = 1) { requestSecondFactorCodeUseCase(email, VerifiableAction.LOGIN_OR_CLIENT_REGISTRATION) } | ||
} | ||
|
||
@Test | ||
fun `given missing 2fa, when logging in, then email should be enabled and not loading`() = runTest { | ||
val email = "[email protected]" | ||
coEvery { loginUseCase(any(), any(), any(), any(), any()) } returns AuthenticationResult.Failure.InvalidCredentials.Missing2FA | ||
coEvery { requestSecondFactorCodeUseCase(any(), any()) } returns RequestSecondFactorVerificationCodeUseCase.Result.Success | ||
|
||
loginViewModel.onUserIdentifierChange(TextFieldValue(email)) | ||
loginViewModel.onPasswordChange(TextFieldValue("somePassword")) | ||
loginViewModel.login(onSuccess) | ||
advanceUntilIdle() | ||
|
||
loginViewModel.loginState.emailLoginLoading shouldBe false | ||
loginViewModel.loginState.emailLoginEnabled shouldBe true | ||
} | ||
|
||
@Test | ||
fun `given login fails with 2fa missing and 2fa request succeeds, when logging in, then should request user input`() = runTest { | ||
val email = "[email protected]" | ||
|