mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
adding test around login with token
This commit is contained in:
parent
e77688b3f4
commit
87a0957d9a
2 changed files with 26 additions and 0 deletions
|
@ -76,6 +76,7 @@ private const val AN_EMAIL = "hello@example.com"
|
|||
private const val A_PASSWORD = "a-password"
|
||||
private const val A_USERNAME = "hello-world"
|
||||
private const val A_MATRIX_ID = "@$A_USERNAME:matrix.org"
|
||||
private const val A_LOGIN_TOKEN = "a-login-token"
|
||||
|
||||
class OnboardingViewModelTest {
|
||||
|
||||
|
@ -141,6 +142,25 @@ class OnboardingViewModelTest {
|
|||
.finish()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given can successfully login in with token, when logging in with token, then emits AccountSignedIn`() = runTest {
|
||||
val test = viewModel.test()
|
||||
fakeAuthenticationService.givenLoginWizard(fakeLoginWizard)
|
||||
fakeLoginWizard.givenLoginWithTokenResult(A_LOGIN_TOKEN, fakeSession)
|
||||
givenInitialisesSession(fakeSession)
|
||||
|
||||
viewModel.handle(OnboardingAction.LoginWithToken(A_LOGIN_TOKEN))
|
||||
|
||||
test
|
||||
.assertStatesChanges(
|
||||
initialState,
|
||||
{ copy(isLoading = true) },
|
||||
{ copy(isLoading = false) }
|
||||
)
|
||||
.assertEvents(OnboardingViewEvents.OnAccountSignedIn)
|
||||
.finish()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given registration started with currentThreePid, when handling InitWith, then emits restored session OnSendEmailSuccess`() = runTest {
|
||||
val test = viewModel.test()
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
|
||||
package im.vector.app.test.fakes
|
||||
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coJustRun
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.mockk
|
||||
import org.matrix.android.sdk.api.auth.login.LoginWizard
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
|
||||
class FakeLoginWizard : LoginWizard by mockk() {
|
||||
|
||||
|
@ -27,6 +29,10 @@ class FakeLoginWizard : LoginWizard by mockk() {
|
|||
coJustRun { resetPassword(email) }
|
||||
}
|
||||
|
||||
fun givenLoginWithTokenResult(token: String, result: Session) {
|
||||
coEvery { loginWithToken(token) } returns result
|
||||
}
|
||||
|
||||
fun givenConfirmResetPasswordSuccess(password: String) {
|
||||
coJustRun { resetPasswordMailConfirmed(password) }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue