update test cases

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-06-22 21:42:07 +02:00
parent 55585e9ef0
commit d3286bf6bc
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
3 changed files with 39 additions and 33 deletions

View File

@ -2,7 +2,10 @@ package com.nextcloud.talk.activities
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import com.nextcloud.talk.data.user.model.UserNgEntity import com.nextcloud.talk.data.user.model.UserNgEntity
import org.junit.Assert.assertTrue import com.nextcloud.talk.users.UserManager
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import org.junit.Assert.fail
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
@ -15,39 +18,41 @@ class MainActivityTest {
) )
@Test @Test
suspend fun login() { fun login() {
val sut = activityRule.launchActivity(null) val sut = activityRule.launchActivity(null)
sut.usersRepository.insertUser( sut.userManager.createOrUpdateUser(
UserNgEntity(
0,
"test", "test",
"test", UserManager.UserAttributes(
"http://server/nc", id = 0,
"test", serverUrl = "http://server/nc",
null, currentUser = false,
null, userId = "test",
null, token = "test",
null, displayName = null,
null, pushConfigurationState = null,
false, capabilities = null,
scheduledForDeletion = false certificateAlias = null,
externalSignalingServer = null
) )
) ).subscribe(object : Observer<UserNgEntity?> {
override fun onSubscribe(d: Disposable) {
try { // unused atm
Thread.sleep(2000)
} catch (e: InterruptedException) {
e.printStackTrace()
} }
override fun onNext(user: UserNgEntity) {
sut.runOnUiThread { sut.resetConversationsList() } sut.runOnUiThread { sut.resetConversationsList() }
assertTrue(sut.usersRepository.getUserWithUsernameAndServer("test", "http://server/nc") != null) println("User: " + user.id + " / " + user.userId + " / " + user.baseUrl)
}
try { override fun onError(e: Throwable) {
} catch (e: InterruptedException) { fail("No user created")
e.printStackTrace() }
}
override fun onComplete() {
// unused atm
}
})
} }
} }

View File

@ -143,10 +143,7 @@ public class LoginIT {
onView(withId(R.id.user_name)).check(matches(withText("User One"))); onView(withId(R.id.user_name)).check(matches(withText("User One")));
activityScenario.onActivity(activity -> { activityScenario.onActivity(activity -> {
assertEquals(loginName, Objects.requireNonNull(activity.usersRepository.getActiveUser()).getUserId()); assertEquals(loginName, Objects.requireNonNull(activity.userManager.getCurrentUser()).getUserId());
}); });
} }
} }

View File

@ -303,6 +303,10 @@ class UserManager internal constructor(private val userRepository: UsersReposito
return userRepository.getUserWithIdLiveData(user!!.id) return userRepository.getUserWithIdLiveData(user!!.id)
} }
fun getUserWithUsernameAndServer(username: String, server: String): Observable<UserNgEntity?> {
return userRepository.getUserWithUsernameAndServer(username, server)
}
private fun updateUserData(user: UserNgEntity, userAttributes: UserAttributes) { private fun updateUserData(user: UserNgEntity, userAttributes: UserAttributes) {
updateUserIdIfNeeded(userAttributes, user) updateUserIdIfNeeded(userAttributes, user)
updateTokenIfNeeded(userAttributes, user) updateTokenIfNeeded(userAttributes, user)