Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani committed Feb 21, 2024
1 parent b0273b2 commit 7a7651a
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ WHERE Conversation.mls_group_id IS NOT NULL AND mls_group_state IS 'ESTABLISHED'

getMLSGroupIdByConversationId:
SELECT Conversation.mls_group_id FROM Conversation
WHERE Conversation.qualified_id = :conversationId;
WHERE Conversation.qualified_id = :conversationId
AND Conversation.mls_group_state IS 'ESTABLISHED';

updateConversationReceiptMode:
UPDATE Conversation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,67 @@ class ConversationDAOTest : BaseDatabaseTest() {
)
}

@Test
fun givenNotEstablishedMLSConversationExists_whenGettingE2EIClientInfoByClientId_thenReturnsNull() = runTest {
// given
val clientId = "id0"
userDAO.upsertUser(user1)

clientDao.insertClients(listOf(insertedClient.copy(user1.id, id = clientId), insertedClient.copy(user1.id, id = "id1")))

conversationDAO.insertConversation(conversationEntity1.copy(id = user1.id, type = ConversationEntity.Type.SELF))
conversationDAO.insertConversation(conversationEntity3)
memberDAO.insertMembersWithQualifiedId(
listOf(
MemberEntity(user1.id, MemberEntity.Role.Admin),
),
conversationEntity3.id
)
// then
assertNull(conversationDAO.getE2EIConversationClientInfoByClientId(clientId))
}

@Test
fun givenNotEstablishedMLSConversationExists_whenGettingMLSGroupIdByUserId_thenReturnsNull() = runTest {
// given
val clientId = "id0"
userDAO.upsertUser(user1)
userDAO.upsertUser(user2)

conversationDAO.insertConversation(conversationEntity1.copy(id = user1.id, type = ConversationEntity.Type.SELF))
conversationDAO.insertConversation(conversationEntity3)
memberDAO.insertMembersWithQualifiedId(
listOf(
MemberEntity(user1.id, MemberEntity.Role.Admin),
MemberEntity(user2.id, MemberEntity.Role.Admin),
),
conversationEntity3.id
)
// then
assertNull(conversationDAO.getMLSGroupIdByUserId(user1.id))
}

@Test
fun givenEstablishedMLSConversationExists_whenGettingMLSGroupIdByUserId_thenReturnsMLSGroupId() = runTest {
// given
val expected = (conversationEntity4.protocolInfo as ConversationEntity.ProtocolInfo.MLS).groupId
userDAO.upsertUser(user1)
userDAO.upsertUser(user2)

conversationDAO.insertConversation(conversationEntity1.copy(id = user1.id, type = ConversationEntity.Type.SELF))
conversationDAO.insertConversation(conversationEntity4)
memberDAO.insertMembersWithQualifiedId(
listOf(
MemberEntity(user1.id, MemberEntity.Role.Admin),
MemberEntity(user2.id, MemberEntity.Role.Admin),
),
conversationEntity4.id
)
// then
assertEquals(expected, conversationDAO.getMLSGroupIdByUserId(user1.id))
}


@Test
fun givenMLSSelfConversationDoesNotExists_whenGettingE2EIClientInfoByClientId_thenShouldReturnNull() = runTest {
// given
Expand Down Expand Up @@ -1656,6 +1717,60 @@ class ConversationDAOTest : BaseDatabaseTest() {
assertEquals(false, result)
}

@Test
fun givenOnlyProteusConversation_whenGettingMLSGroupIdByConversationId_thenShouldReturnNull() = runTest {
// given
val conversationId = QualifiedIDEntity("conversationId", "domain")
conversationDAO.insertConversation(conversationEntity1.copy(conversationId))

// when
val result = conversationDAO.getMLSGroupIdByConversationId(conversationId)

// then
assertNull(result)
}

@Test
fun givenNotEstablishedMLSConversation_whenGettingMLSGroupIdByConversationId_thenShouldReturnNull() = runTest {
// given
val conversationId = QualifiedIDEntity("conversationId", "domain")
conversationDAO.insertConversation(conversationEntity3.copy(conversationId))

// when
val result = conversationDAO.getMLSGroupIdByConversationId(conversationId)

// then
assertNull(result)
}

@Test
fun givenEstablishedMLSConversation_whenGettingMLSGroupIdByConversationId_thenShouldReturnMLSGroupId() = runTest {
// given
val expected = (conversationEntity4.protocolInfo as ConversationEntity.ProtocolInfo.MLS).groupId
val conversationId = QualifiedIDEntity("conversationId", "domain")
conversationDAO.insertConversation(conversationEntity4.copy(conversationId))

// when
val result = conversationDAO.getMLSGroupIdByConversationId(conversationId)

// then
assertEquals(expected, result)
}

@Test
fun givenEstablishedMLSConversation_whenGettingMLSGroupIdByUserId_thenShouldReturnMLSGroupId() = runTest {
// given
val expected = (conversationEntity4.protocolInfo as ConversationEntity.ProtocolInfo.MLS).groupId
val conversationId = QualifiedIDEntity("conversationId", "domain")
conversationDAO.insertConversation(conversationEntity4.copy(conversationId))

// when
val result = conversationDAO.getMLSGroupIdByConversationId(conversationId)

// then
assertEquals(expected, result)
}

private fun ConversationEntity.toViewEntity(userEntity: UserEntity? = null): ConversationViewEntity {
val protocol: ConversationEntity.Protocol
val mlsGroupId: String?
Expand Down

0 comments on commit 7a7651a

Please sign in to comment.