Skip to content

Commit

Permalink
fix: adding participants offline + nfcg new edge case (WPB-4648) (#2053)
Browse files Browse the repository at this point in the history
* fix: adding participants offline + nfcg new edge case (WPB-4648) (#2052)

* fix: add new case for offline handling

* fix: add new case for offline handling test cov

* fix: add new case for offline handling test cov

* Empty-Commit

---------

Co-authored-by: Yamil Medina <yamilmedina@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and yamilmedina authored Sep 14, 2023
1 parent f847369 commit b2a859c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,17 @@ internal class ConversationGroupRepositoryImpl(
userIdList,
apiResult.value as NetworkFailure.FederatedBackendFailure.RetryableFailure
)
// edge case, in case backend goes 🍌 and returns non-matching domains
if (failedUsers.isEmpty()) Either.Left(apiResult.value)
tryAddMembersToCloudAndStorage(validUsers, conversationId, failedUsers.toSet())
when (failedUsers.isNotEmpty()) {
true -> tryAddMembersToCloudAndStorage(validUsers, conversationId, failedUsers.toSet())
false -> {
newGroupConversationSystemMessagesCreator.value.conversationFailedToAddMembers(
conversationId,
(validUsers + failedUsers).toSet()
).flatMap {
Either.Left(apiResult.value)
}
}
}
} else {
newGroupConversationSystemMessagesCreator.value.conversationFailedToAddMembers(
conversationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,44 @@ class ConversationGroupRepositoryTest {
.wasInvoked(once)
}

@Test
fun givenAConversationFailsWithUnreachableAndNotFromUsersInRequest_whenAddingMembers_thenRetryIsNotExecutedAndCreateSysMessage() =
runTest {
// given
val (arrangement, conversationGroupRepository) = Arrangement()
.withConversationDetailsById(TestConversation.CONVERSATION)
.withProtocolInfoById(PROTEUS_PROTOCOL_INFO)
.withFetchUsersIfUnknownByIdsSuccessful()
.withAddMemberAPIFailsFirstWithUnreachableThenSucceed(
arrayOf(FEDERATION_ERROR_UNREACHABLE_DOMAINS, FEDERATION_ERROR_UNREACHABLE_DOMAINS)
)
.withSuccessfulHandleMemberJoinEvent()
.withInsertFailedToAddSystemMessageSuccess()
.arrange()

// when
val expectedInitialUsersNotFromUnreachableInformed = listOf(TestConversation.USER_1)
conversationGroupRepository.addMembers(expectedInitialUsersNotFromUnreachableInformed, TestConversation.ID).shouldFail()

// then
verify(arrangement.conversationApi)
.suspendFunction(arrangement.conversationApi::addMember)
.with(anything())
.wasInvoked(exactly = once)

verify(arrangement.memberJoinEventHandler)
.suspendFunction(arrangement.memberJoinEventHandler::handle)
.with(anything())
.wasNotInvoked()

verify(arrangement.newGroupConversationSystemMessagesCreator)
.suspendFunction(arrangement.newGroupConversationSystemMessagesCreator::conversationFailedToAddMembers)
.with(anything(), matching {
it.containsAll(expectedInitialUsersNotFromUnreachableInformed)
})
.wasInvoked(once)
}

private class Arrangement :
MemberDAOArrangement by MemberDAOArrangementImpl() {

Expand Down

0 comments on commit b2a859c

Please sign in to comment.