adding test around login with token
This commit is contained in:
parent
e77688b3f4
commit
87a0957d9a
@ -76,6 +76,7 @@ private const val AN_EMAIL = "hello@example.com"
|
|||||||
private const val A_PASSWORD = "a-password"
|
private const val A_PASSWORD = "a-password"
|
||||||
private const val A_USERNAME = "hello-world"
|
private const val A_USERNAME = "hello-world"
|
||||||
private const val A_MATRIX_ID = "@$A_USERNAME:matrix.org"
|
private const val A_MATRIX_ID = "@$A_USERNAME:matrix.org"
|
||||||
|
private const val A_LOGIN_TOKEN = "a-login-token"
|
||||||
|
|
||||||
class OnboardingViewModelTest {
|
class OnboardingViewModelTest {
|
||||||
|
|
||||||
@ -141,6 +142,25 @@ class OnboardingViewModelTest {
|
|||||||
.finish()
|
.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
|
@Test
|
||||||
fun `given registration started with currentThreePid, when handling InitWith, then emits restored session OnSendEmailSuccess`() = runTest {
|
fun `given registration started with currentThreePid, when handling InitWith, then emits restored session OnSendEmailSuccess`() = runTest {
|
||||||
val test = viewModel.test()
|
val test = viewModel.test()
|
||||||
|
@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
package im.vector.app.test.fakes
|
package im.vector.app.test.fakes
|
||||||
|
|
||||||
|
import io.mockk.coEvery
|
||||||
import io.mockk.coJustRun
|
import io.mockk.coJustRun
|
||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import org.matrix.android.sdk.api.auth.login.LoginWizard
|
import org.matrix.android.sdk.api.auth.login.LoginWizard
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
|
||||||
class FakeLoginWizard : LoginWizard by mockk() {
|
class FakeLoginWizard : LoginWizard by mockk() {
|
||||||
|
|
||||||
@ -27,6 +29,10 @@ class FakeLoginWizard : LoginWizard by mockk() {
|
|||||||
coJustRun { resetPassword(email) }
|
coJustRun { resetPassword(email) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenLoginWithTokenResult(token: String, result: Session) {
|
||||||
|
coEvery { loginWithToken(token) } returns result
|
||||||
|
}
|
||||||
|
|
||||||
fun givenConfirmResetPasswordSuccess(password: String) {
|
fun givenConfirmResetPasswordSuccess(password: String) {
|
||||||
coJustRun { resetPasswordMailConfirmed(password) }
|
coJustRun { resetPasswordMailConfirmed(password) }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user