diff --git a/app/src/androidTest/java/com/nextcloud/talk/data/database/dao/ChatBlocksDaoTest.kt b/app/src/androidTest/java/com/nextcloud/talk/data/database/dao/ChatBlocksDaoTest.kt index 4ed2687a52..f832a97d53 100644 --- a/app/src/androidTest/java/com/nextcloud/talk/data/database/dao/ChatBlocksDaoTest.kt +++ b/app/src/androidTest/java/com/nextcloud/talk/data/database/dao/ChatBlocksDaoTest.kt @@ -12,7 +12,12 @@ import androidx.room.Room import androidx.test.core.app.ApplicationProvider import androidx.test.runner.AndroidJUnit4 import com.nextcloud.talk.data.database.model.ChatBlockEntity +import com.nextcloud.talk.data.database.model.ConversationEntity import com.nextcloud.talk.data.source.local.TalkDatabase +import com.nextcloud.talk.data.user.UsersDao +import com.nextcloud.talk.data.user.model.UserEntity +import com.nextcloud.talk.models.json.conversations.ConversationEnums +import com.nextcloud.talk.models.json.participants.Participant import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import org.junit.After @@ -23,6 +28,8 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class ChatBlocksDaoTest { + private lateinit var usersDao: UsersDao + private lateinit var conversationsDao: ConversationsDao private lateinit var chatBlocksDao: ChatBlocksDao private lateinit var db: TalkDatabase private val tag = ChatBlocksDaoTest::class.java.simpleName @@ -34,6 +41,8 @@ class ChatBlocksDaoTest { context, TalkDatabase::class.java ).build() + usersDao = db.usersDao() + conversationsDao = db.conversationsDao() chatBlocksDao = db.chatBlocksDao() } @@ -44,57 +53,94 @@ class ChatBlocksDaoTest { fun testGetConnectedChatBlocks() = runTest { + usersDao.saveUser(createUserEntity("account1", "Account 1")) + val account1 = usersDao.getUserWithUserId("account1").blockingGet() + + conversationsDao.upsertConversations( + listOf( + createConversationEntity( + accountId = account1.id, + "abc", + roomName = "Conversation One" + ), + createConversationEntity( + accountId = account1.id, + "def", + roomName = "Conversation Two" + ), + ) + ) + + val conversation1 = conversationsDao.getConversationsForUser(account1.id).first()[0] + val conversation2 = conversationsDao.getConversationsForUser(account1.id).first()[1] + val searchedChatBlock = ChatBlockEntity( - internalConversationId = "1", + internalConversationId = conversation1.internalId, + accountId = conversation1.accountId, + token = conversation1.token, oldestMessageId = 50, newestMessageId = 60, hasHistory = true ) val chatBlockTooOld = ChatBlockEntity( - internalConversationId = "1", + internalConversationId = conversation1.internalId, + accountId = conversation1.accountId, + token = conversation1.token, oldestMessageId = 10, newestMessageId = 20, hasHistory = true ) val chatBlockOverlap1 = ChatBlockEntity( - internalConversationId = "1", + internalConversationId = conversation1.internalId, + accountId = conversation1.accountId, + token = conversation1.token, oldestMessageId = 45, newestMessageId = 55, hasHistory = true ) val chatBlockWithin = ChatBlockEntity( - internalConversationId = "1", + internalConversationId = conversation1.internalId, + accountId = conversation1.accountId, + token = conversation1.token, oldestMessageId = 52, newestMessageId = 58, hasHistory = true ) val chatBlockOverall = ChatBlockEntity( - internalConversationId = "1", + internalConversationId = conversation1.internalId, + accountId = conversation1.accountId, + token = conversation1.token, oldestMessageId = 1, newestMessageId = 99, hasHistory = true ) val chatBlockOverlap2 = ChatBlockEntity( - internalConversationId = "1", + internalConversationId = conversation1.internalId, + accountId = conversation1.accountId, + token = conversation1.token, oldestMessageId = 59, newestMessageId = 70, hasHistory = true ) val chatBlockTooNew = ChatBlockEntity( - internalConversationId = "1", + internalConversationId = conversation1.internalId, + accountId = conversation1.accountId, + token = conversation1.token, oldestMessageId = 80, newestMessageId = 90, hasHistory = true ) val chatBlockWithinButOtherConversation = ChatBlockEntity( - internalConversationId = "2", + internalConversationId = conversation2.internalId, + accountId = conversation2.accountId, + token = conversation2.token, oldestMessageId = 53, newestMessageId = 57, hasHistory = true @@ -111,11 +157,77 @@ class ChatBlocksDaoTest { chatBlocksDao.upsertChatBlock(chatBlockWithinButOtherConversation) val results = chatBlocksDao.getConnectedChatBlocks( - "1", + conversation1.internalId, searchedChatBlock.oldestMessageId, searchedChatBlock.newestMessageId ) assertEquals(5, results.first().size) } + + private fun createUserEntity(userId: String, userName: String) = + UserEntity( + userId = userId, + username = userName, + baseUrl = null, + token = null, + displayName = null, + pushConfigurationState = null, + capabilities = null, + serverVersion = null, + clientCertificate = null, + externalSignalingServer = null, + current = java.lang.Boolean.FALSE, + scheduledForDeletion = java.lang.Boolean.FALSE + ) + + private fun createConversationEntity(accountId: Long, token: String, roomName: String): ConversationEntity { + return ConversationEntity( + internalId = "$accountId@$token", + accountId = accountId, + token = token, + name = roomName, + actorId = "", + actorType = "", + messageExpiration = 0, + unreadMessages = 0, + statusMessage = null, + lastMessage = null, + canDeleteConversation = false, + canLeaveConversation = false, + lastCommonReadMessage = 0, + lastReadMessage = 0, + type = ConversationEnums.ConversationType.DUMMY, + status = "", + callFlag = 1, + favorite = false, + lastPing = 0, + hasCall = false, + sessionId = "", + canStartCall = false, + lastActivity = 0, + remoteServer = "", + avatarVersion = "", + unreadMentionDirect = false, + callRecording = 1, + callStartTime = 0, + statusClearAt = 0, + unreadMention = false, + lobbyState = ConversationEnums.LobbyState.LOBBY_STATE_MODERATORS_ONLY, + lobbyTimer = 0, + objectType = ConversationEnums.ObjectType.FILE, + statusIcon = null, + description = "", + displayName = "", + hasPassword = false, + permissions = 0, + notificationCalls = 0, + remoteToken = "", + notificationLevel = ConversationEnums.NotificationLevel.ALWAYS, + conversationReadOnlyState = ConversationEnums.ConversationReadOnlyState.CONVERSATION_READ_ONLY, + hasCustomAvatar = false, + participantType = Participant.ParticipantType.DUMMY, + recordingConsentRequired = 1 + ) + } } diff --git a/app/src/androidTest/java/com/nextcloud/talk/data/database/dao/ChatMessagesDaoTest.kt b/app/src/androidTest/java/com/nextcloud/talk/data/database/dao/ChatMessagesDaoTest.kt index 58d2f8bab7..7b3f6876d3 100644 --- a/app/src/androidTest/java/com/nextcloud/talk/data/database/dao/ChatMessagesDaoTest.kt +++ b/app/src/androidTest/java/com/nextcloud/talk/data/database/dao/ChatMessagesDaoTest.kt @@ -12,11 +12,14 @@ import android.util.Log import androidx.room.Room import androidx.test.core.app.ApplicationProvider import androidx.test.runner.AndroidJUnit4 +import com.nextcloud.talk.chat.data.model.ChatMessage import com.nextcloud.talk.data.database.model.ChatMessageEntity import com.nextcloud.talk.data.database.model.ConversationEntity import com.nextcloud.talk.data.source.local.TalkDatabase import com.nextcloud.talk.data.user.UsersDao import com.nextcloud.talk.data.user.model.UserEntity +import com.nextcloud.talk.models.json.conversations.ConversationEnums +import com.nextcloud.talk.models.json.participants.Participant import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import org.junit.After @@ -178,7 +181,48 @@ class ChatMessagesDaoTest { internalId = "$accountId@$token", accountId = accountId, token = token, - name = roomName + name = roomName, + actorId = "", + actorType = "", + messageExpiration = 0, + unreadMessages = 0, + statusMessage = null, + lastMessage = null, + canDeleteConversation = false, + canLeaveConversation = false, + lastCommonReadMessage = 0, + lastReadMessage = 0, + type = ConversationEnums.ConversationType.DUMMY, + status = "", + callFlag = 1, + favorite = false, + lastPing = 0, + hasCall = false, + sessionId = "", + canStartCall = false, + lastActivity = 0, + remoteServer = "", + avatarVersion = "", + unreadMentionDirect = false, + callRecording = 1, + callStartTime = 0, + statusClearAt = 0, + unreadMention = false, + lobbyState = ConversationEnums.LobbyState.LOBBY_STATE_MODERATORS_ONLY, + lobbyTimer = 0, + objectType = ConversationEnums.ObjectType.FILE, + statusIcon = null, + description = "", + displayName = "", + hasPassword = false, + permissions = 0, + notificationCalls = 0, + remoteToken = "", + notificationLevel = ConversationEnums.NotificationLevel.ALWAYS, + conversationReadOnlyState = ConversationEnums.ConversationReadOnlyState.CONVERSATION_READ_ONLY, + hasCustomAvatar = false, + participantType = Participant.ParticipantType.DUMMY, + recordingConsentRequired = 1 ) } @@ -200,7 +244,25 @@ class ChatMessagesDaoTest { id = id, message = message, reactions = reactions, - reactionsSelf = reactionsSelf + reactionsSelf = reactionsSelf, + deleted = false, + token = "", + actorId = "", + actorType = "", + accountId = 1, + messageParameters = null, + messageType = "", + parentMessageId = null, + systemMessageType = ChatMessage.SystemMessageType.DUMMY, + replyable = false, + timestamp = 0, + expirationTimestamp = 0, + actorDisplayName = "", + lastEditActorType = null, + lastEditTimestamp = null, + renderMarkdown = true, + lastEditActorId = "", + lastEditActorDisplayName = "" ) return entity }