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( "test",
0, UserManager.UserAttributes(
"test", id = 0,
"test", serverUrl = "http://server/nc",
"http://server/nc", currentUser = false,
"test", userId = "test",
null, token = "test",
null, displayName = null,
null, pushConfigurationState = null,
null, capabilities = null,
null, certificateAlias = null,
false, externalSignalingServer = null
scheduledForDeletion = false
) )
) ).subscribe(object : Observer<UserNgEntity?> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
try { override fun onNext(user: UserNgEntity) {
Thread.sleep(2000) sut.runOnUiThread { sut.resetConversationsList() }
} catch (e: InterruptedException) {
e.printStackTrace()
}
sut.runOnUiThread { sut.resetConversationsList() } println("User: " + user.id + " / " + user.userId + " / " + user.baseUrl)
}
assertTrue(sut.usersRepository.getUserWithUsernameAndServer("test", "http://server/nc") != null) override fun onError(e: Throwable) {
fail("No user created")
}
try { override fun onComplete() {
} catch (e: InterruptedException) { // unused atm
e.printStackTrace() }
} })
} }
} }

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)