Refactor multi logs support (#165)

This commit is contained in:
Mikołaj Pich
2018-10-14 15:42:36 +02:00
committed by Rafał Borcz
parent 5cd8ed88c0
commit bb69d1b643
19 changed files with 433 additions and 122 deletions

View File

@ -22,10 +22,10 @@ class SessionRemoteTest {
@Test
fun testRemoteAll() {
doReturn(Single.just(listOf(Pupil("", "", "", "test", "", ""))))
doReturn(Single.just(listOf(Pupil("", "", "", "test", "", "", Api.LoginType.AUTO))))
.`when`(mockApi).getPupils()
val students = SessionRemote(mockApi).getConnectedStudents("", "", "").blockingGet()
val students = SessionRemote(mockApi).getConnectedStudents("", "", "", "http://fakelog.cf").blockingGet()
assertEquals(1, students.size)
assertEquals("test", students.first().studentName)
}

View File

@ -1,6 +1,7 @@
package io.github.wulkanowy.ui.login.form
import io.github.wulkanowy.TestSchedulers
import io.github.wulkanowy.api.Api
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.SessionRepository
import io.github.wulkanowy.ui.login.LoginErrorHandler
@ -39,65 +40,51 @@ class LoginFormPresenterTest {
}
@Test
fun emptyEmailLoginTest() {
presenter.attemptLogin("", "test123", "test")
fun emptyNicknameLoginTest() {
presenter.attemptLogin("", "test123", "test", "https://fakelog.cf")
verify(loginFormView).setErrorEmailRequired()
verify(loginFormView).setErrorNicknameRequired()
verify(loginFormView, never()).setErrorPassRequired(false)
verify(loginFormView, never()).setErrorSymbolRequire()
verify(loginFormView, never()).setErrorEmailInvalid()
verify(loginFormView, never()).setErrorPassInvalid(false)
}
@Test
fun invalidEmailLoginTest() {
presenter.attemptLogin("test", "test123", "test")
verify(loginFormView, never()).setErrorEmailRequired()
verify(loginFormView, never()).setErrorPassRequired(false)
verify(loginFormView, never()).setErrorSymbolRequire()
verify(loginFormView).setErrorEmailInvalid()
verify(loginFormView, never()).setErrorPassInvalid(false)
}
@Test
fun emptyPassLoginTest() {
presenter.attemptLogin("@", "", "test")
presenter.attemptLogin("@", "", "test", "https://fakelog.cf")
verify(loginFormView, never()).setErrorEmailRequired()
verify(loginFormView, never()).setErrorNicknameRequired()
verify(loginFormView).setErrorPassRequired(true)
verify(loginFormView, never()).setErrorSymbolRequire()
verify(loginFormView, never()).setErrorEmailInvalid()
verify(loginFormView, never()).setErrorPassInvalid(false)
}
@Test
fun invalidPassLoginTest() {
presenter.attemptLogin("@", "123", "test")
presenter.attemptLogin("@", "123", "test", "https://fakelog.cf")
verify(loginFormView, never()).setErrorEmailRequired()
verify(loginFormView, never()).setErrorNicknameRequired()
verify(loginFormView, never()).setErrorPassRequired(true)
verify(loginFormView, never()).setErrorSymbolRequire()
verify(loginFormView, never()).setErrorEmailInvalid()
verify(loginFormView).setErrorPassInvalid(true)
}
@Test
fun emptySymbolLoginTest() {
doReturn(Single.just(emptyList<Student>()))
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString())
presenter.attemptLogin("@", "12345", "")
presenter.attemptLogin("@", "12345", "")
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
verify(loginFormView).setErrorSymbolRequire()
}
@Test
fun loginTest() {
val studentTest = Student(email = "test@", password = "123")
val studentTest = Student(email = "test@", password = "123", endpoint = "https://fakelog.cf", loginType = "AUTO")
doReturn(Single.just(listOf(studentTest)))
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString())
presenter.attemptLogin("@", "12345", "test")
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
verify(loginFormView).hideSoftKeyboard()
verify(loginFormView).showLoginProgress(true)
@ -109,8 +96,8 @@ class LoginFormPresenterTest {
@Test
fun loginEmptyTest() {
doReturn(Single.just(emptyList<Student>()))
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString())
presenter.attemptLogin("@", "12345", "test")
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
verify(loginFormView).hideSoftKeyboard()
verify(loginFormView).showLoginProgress(true)
@ -122,9 +109,9 @@ class LoginFormPresenterTest {
@Test
fun loginEmptyTwiceTest() {
doReturn(Single.just(emptyList<Student>()))
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString())
presenter.attemptLogin("@", "12345", "")
presenter.attemptLogin("@", "12345", "test")
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
verify(loginFormView, times(2)).hideSoftKeyboard()
verify(loginFormView, times(2)).showLoginProgress(true)
@ -139,8 +126,8 @@ class LoginFormPresenterTest {
fun loginErrorTest() {
val testException = RuntimeException()
doReturn(Single.error<List<Student>>(testException))
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString())
presenter.attemptLogin("@", "12345", "test")
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
verify(loginFormView).hideSoftKeyboard()
verify(loginFormView).showLoginProgress(true)

View File

@ -1,6 +1,7 @@
package io.github.wulkanowy.ui.login.options
import io.github.wulkanowy.TestSchedulers
import io.github.wulkanowy.api.Api
import io.github.wulkanowy.data.ErrorHandler
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.SessionRepository
@ -25,7 +26,7 @@ class LoginOptionsPresenterTest {
private lateinit var presenter: LoginOptionsPresenter
private val testStudent by lazy { Student(email = "test", password = "test123") }
private val testStudent by lazy { Student(email = "test", password = "test123", endpoint = "https://fakelog.cf", loginType = "AUTO") }
private val testException by lazy { RuntimeException("Problem") }