mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-09 22:04:24 +01:00
fix tests
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
8885b999ca
commit
82b3eb3647
@ -12,7 +12,12 @@ import androidx.room.Room
|
|||||||
import androidx.test.core.app.ApplicationProvider
|
import androidx.test.core.app.ApplicationProvider
|
||||||
import androidx.test.runner.AndroidJUnit4
|
import androidx.test.runner.AndroidJUnit4
|
||||||
import com.nextcloud.talk.data.database.model.ChatBlockEntity
|
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.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.flow.first
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
@ -23,6 +28,8 @@ import org.junit.runner.RunWith
|
|||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class ChatBlocksDaoTest {
|
class ChatBlocksDaoTest {
|
||||||
|
private lateinit var usersDao: UsersDao
|
||||||
|
private lateinit var conversationsDao: ConversationsDao
|
||||||
private lateinit var chatBlocksDao: ChatBlocksDao
|
private lateinit var chatBlocksDao: ChatBlocksDao
|
||||||
private lateinit var db: TalkDatabase
|
private lateinit var db: TalkDatabase
|
||||||
private val tag = ChatBlocksDaoTest::class.java.simpleName
|
private val tag = ChatBlocksDaoTest::class.java.simpleName
|
||||||
@ -34,6 +41,8 @@ class ChatBlocksDaoTest {
|
|||||||
context,
|
context,
|
||||||
TalkDatabase::class.java
|
TalkDatabase::class.java
|
||||||
).build()
|
).build()
|
||||||
|
usersDao = db.usersDao()
|
||||||
|
conversationsDao = db.conversationsDao()
|
||||||
chatBlocksDao = db.chatBlocksDao()
|
chatBlocksDao = db.chatBlocksDao()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,57 +53,94 @@ class ChatBlocksDaoTest {
|
|||||||
fun testGetConnectedChatBlocks() =
|
fun testGetConnectedChatBlocks() =
|
||||||
runTest {
|
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(
|
val searchedChatBlock = ChatBlockEntity(
|
||||||
internalConversationId = "1",
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
oldestMessageId = 50,
|
oldestMessageId = 50,
|
||||||
newestMessageId = 60,
|
newestMessageId = 60,
|
||||||
hasHistory = true
|
hasHistory = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val chatBlockTooOld = ChatBlockEntity(
|
val chatBlockTooOld = ChatBlockEntity(
|
||||||
internalConversationId = "1",
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
oldestMessageId = 10,
|
oldestMessageId = 10,
|
||||||
newestMessageId = 20,
|
newestMessageId = 20,
|
||||||
hasHistory = true
|
hasHistory = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val chatBlockOverlap1 = ChatBlockEntity(
|
val chatBlockOverlap1 = ChatBlockEntity(
|
||||||
internalConversationId = "1",
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
oldestMessageId = 45,
|
oldestMessageId = 45,
|
||||||
newestMessageId = 55,
|
newestMessageId = 55,
|
||||||
hasHistory = true
|
hasHistory = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val chatBlockWithin = ChatBlockEntity(
|
val chatBlockWithin = ChatBlockEntity(
|
||||||
internalConversationId = "1",
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
oldestMessageId = 52,
|
oldestMessageId = 52,
|
||||||
newestMessageId = 58,
|
newestMessageId = 58,
|
||||||
hasHistory = true
|
hasHistory = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val chatBlockOverall = ChatBlockEntity(
|
val chatBlockOverall = ChatBlockEntity(
|
||||||
internalConversationId = "1",
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
oldestMessageId = 1,
|
oldestMessageId = 1,
|
||||||
newestMessageId = 99,
|
newestMessageId = 99,
|
||||||
hasHistory = true
|
hasHistory = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val chatBlockOverlap2 = ChatBlockEntity(
|
val chatBlockOverlap2 = ChatBlockEntity(
|
||||||
internalConversationId = "1",
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
oldestMessageId = 59,
|
oldestMessageId = 59,
|
||||||
newestMessageId = 70,
|
newestMessageId = 70,
|
||||||
hasHistory = true
|
hasHistory = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val chatBlockTooNew = ChatBlockEntity(
|
val chatBlockTooNew = ChatBlockEntity(
|
||||||
internalConversationId = "1",
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
oldestMessageId = 80,
|
oldestMessageId = 80,
|
||||||
newestMessageId = 90,
|
newestMessageId = 90,
|
||||||
hasHistory = true
|
hasHistory = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val chatBlockWithinButOtherConversation = ChatBlockEntity(
|
val chatBlockWithinButOtherConversation = ChatBlockEntity(
|
||||||
internalConversationId = "2",
|
internalConversationId = conversation2.internalId,
|
||||||
|
accountId = conversation2.accountId,
|
||||||
|
token = conversation2.token,
|
||||||
oldestMessageId = 53,
|
oldestMessageId = 53,
|
||||||
newestMessageId = 57,
|
newestMessageId = 57,
|
||||||
hasHistory = true
|
hasHistory = true
|
||||||
@ -111,11 +157,77 @@ class ChatBlocksDaoTest {
|
|||||||
chatBlocksDao.upsertChatBlock(chatBlockWithinButOtherConversation)
|
chatBlocksDao.upsertChatBlock(chatBlockWithinButOtherConversation)
|
||||||
|
|
||||||
val results = chatBlocksDao.getConnectedChatBlocks(
|
val results = chatBlocksDao.getConnectedChatBlocks(
|
||||||
"1",
|
conversation1.internalId,
|
||||||
searchedChatBlock.oldestMessageId,
|
searchedChatBlock.oldestMessageId,
|
||||||
searchedChatBlock.newestMessageId
|
searchedChatBlock.newestMessageId
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(5, results.first().size)
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,14 @@ import android.util.Log
|
|||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.test.core.app.ApplicationProvider
|
import androidx.test.core.app.ApplicationProvider
|
||||||
import androidx.test.runner.AndroidJUnit4
|
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.ChatMessageEntity
|
||||||
import com.nextcloud.talk.data.database.model.ConversationEntity
|
import com.nextcloud.talk.data.database.model.ConversationEntity
|
||||||
import com.nextcloud.talk.data.source.local.TalkDatabase
|
import com.nextcloud.talk.data.source.local.TalkDatabase
|
||||||
import com.nextcloud.talk.data.user.UsersDao
|
import com.nextcloud.talk.data.user.UsersDao
|
||||||
import com.nextcloud.talk.data.user.model.UserEntity
|
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.flow.first
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
@ -178,7 +181,48 @@ class ChatMessagesDaoTest {
|
|||||||
internalId = "$accountId@$token",
|
internalId = "$accountId@$token",
|
||||||
accountId = accountId,
|
accountId = accountId,
|
||||||
token = token,
|
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,
|
id = id,
|
||||||
message = message,
|
message = message,
|
||||||
reactions = reactions,
|
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
|
return entity
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user