Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Split NoCommonProtocol error 🍒 #2834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,17 @@ sealed interface CoreFailure {
* No common Protocol found in order to establish a conversation between parties.
* Could be, for example, that the desired user only supports Proteus, but we only support MLS.
*/
data object NoCommonProtocolFound : FeatureFailure()
sealed class NoCommonProtocolFound : FeatureFailure() {
/**
* SelfClient needs to update to support MLS
*/
data object SelfNeedToUpdate : NoCommonProtocolFound()

/**
* Other User needs to update to support MLS
*/
data object OtherNeedToUpdate : NoCommonProtocolFound()
}
}

sealed class NetworkFailure : CoreFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ internal class OneOnOneProtocolSelectorImpl(
return when {
commonProtocols.contains(SupportedProtocol.MLS) -> Either.Right(SupportedProtocol.MLS)
commonProtocols.contains(SupportedProtocol.PROTEUS) -> Either.Right(SupportedProtocol.PROTEUS)
else -> Either.Left(CoreFailure.NoCommonProtocolFound)
selfUserProtocols.contains(SupportedProtocol.MLS) -> Either.Left(CoreFailure.NoCommonProtocolFound.OtherNeedToUpdate)
else -> Either.Left(CoreFailure.NoCommonProtocolFound.SelfNeedToUpdate)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GetOrCreateOneToOneConversationUseCaseTest {
val (_, useCase) = arrange {
withObserveOneToOneConversationWithOtherUserReturning(Either.Left(StorageFailure.DataNotFound))
withUserByIdReturning(OTHER_USER.right())
withResolveOneOnOneConversationWithUserReturning(Either.Left(CoreFailure.NoCommonProtocolFound))
withResolveOneOnOneConversationWithUserReturning(Either.Left(CoreFailure.NoCommonProtocolFound.SelfNeedToUpdate))
}

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,22 @@ class OneOnOneProtocolSelectorTest {

oneOnOneProtocolSelector.getProtocolForUser(TestUser.USER_ID)
.shouldFail {
assertIs<CoreFailure.NoCommonProtocolFound>(it)
assertIs<CoreFailure.NoCommonProtocolFound.OtherNeedToUpdate>(it)
}
}

@Test
fun givenUsersHaveNoProtocolInCommon_thenShouldReturnNoCommonProtocol_2() = runTest {
val failure = StorageFailure.DataNotFound
val (_, oneOnOneProtocolSelector) = arrange {
withSelfUserReturning(TestUser.SELF.copy(supportedProtocols = setOf(SupportedProtocol.PROTEUS)))
withUserByIdReturning(Either.Right(TestUser.OTHER.copy(supportedProtocols = setOf(SupportedProtocol.MLS))))
withGetDefaultProtocolReturning(failure.left())
}

oneOnOneProtocolSelector.getProtocolForUser(TestUser.USER_ID)
.shouldFail {
assertIs<CoreFailure.NoCommonProtocolFound.SelfNeedToUpdate>(it)
}
}

Expand Down
Loading