adding test around login with username and password
This commit is contained in:
parent
87a0957d9a
commit
a32a78751a
@ -75,6 +75,7 @@ private val DEFAULT_SELECTED_HOMESERVER_STATE = SELECTED_HOMESERVER_STATE.copy(u
|
|||||||
private const val AN_EMAIL = "hello@example.com"
|
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_DEVICE_NAME = "a-device-name"
|
||||||
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"
|
private const val A_LOGIN_TOKEN = "a-login-token"
|
||||||
|
|
||||||
@ -161,6 +162,25 @@ class OnboardingViewModelTest {
|
|||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given can login with username and password, when logging in, then emits AccountSignedIn`() = runTest {
|
||||||
|
val test = viewModel.test()
|
||||||
|
fakeAuthenticationService.givenLoginWizard(fakeLoginWizard)
|
||||||
|
fakeLoginWizard.givenLoginSuccess(A_USERNAME, A_PASSWORD, A_DEVICE_NAME, fakeSession)
|
||||||
|
givenInitialisesSession(fakeSession)
|
||||||
|
|
||||||
|
viewModel.handle(OnboardingAction.AuthenticateAction.Login(A_USERNAME, A_PASSWORD, A_DEVICE_NAME))
|
||||||
|
|
||||||
|
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()
|
||||||
|
@ -33,6 +33,10 @@ class FakeLoginWizard : LoginWizard by mockk() {
|
|||||||
coEvery { loginWithToken(token) } returns result
|
coEvery { loginWithToken(token) } returns result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenLoginSuccess(username: String, password: String, deviceName: String, result: Session) {
|
||||||
|
coEvery { login(username, password, deviceName) } returns result
|
||||||
|
}
|
||||||
|
|
||||||
fun givenConfirmResetPasswordSuccess(password: String) {
|
fun givenConfirmResetPasswordSuccess(password: String) {
|
||||||
coJustRun { resetPasswordMailConfirmed(password) }
|
coJustRun { resetPasswordMailConfirmed(password) }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user