-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/handle-federation-not-enabled-cherry-…
…pick
- Loading branch information
Showing
16 changed files
with
491 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...in/com/wire/kalium/logic/feature/message/GetSearchedConversationMessagePositionUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.feature.message | ||
|
||
import com.wire.kalium.logic.CoreFailure | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.data.message.MessageRepository | ||
import com.wire.kalium.logic.functional.fold | ||
|
||
/** | ||
* Gets the Selected Message Position from Search | ||
* | ||
* @param conversationId [ConversationId] the id of the conversation where the search is happening. | ||
* @param messageId [String] the id of the selected message from search. | ||
* | ||
* @result [Result] Success with Int position. Failure with StorageFailure. | ||
*/ | ||
interface GetSearchedConversationMessagePositionUseCase { | ||
|
||
suspend operator fun invoke( | ||
conversationId: ConversationId, | ||
messageId: String | ||
): Result | ||
|
||
sealed interface Result { | ||
data class Success(val position: Int) : Result | ||
data class Failure(val cause: CoreFailure) : Result | ||
} | ||
} | ||
|
||
internal class GetSearchedConversationMessagePositionUseCaseImpl internal constructor( | ||
private val messageRepository: MessageRepository | ||
) : GetSearchedConversationMessagePositionUseCase { | ||
|
||
override suspend fun invoke( | ||
conversationId: ConversationId, | ||
messageId: String | ||
): GetSearchedConversationMessagePositionUseCase.Result = messageRepository | ||
.getSearchedConversationMessagePosition( | ||
conversationId = conversationId, | ||
messageId = messageId | ||
).fold( | ||
{ GetSearchedConversationMessagePositionUseCase.Result.Failure(it) }, | ||
{ GetSearchedConversationMessagePositionUseCase.Result.Success(it) } | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...kalium/logic/feature/message/message/GetSearchedConversationMessagePositionUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.feature.message.message | ||
|
||
import com.wire.kalium.logic.StorageFailure | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.data.message.MessageRepository | ||
import com.wire.kalium.logic.feature.message.GetSearchedConversationMessagePositionUseCase | ||
import com.wire.kalium.logic.feature.message.GetSearchedConversationMessagePositionUseCaseImpl | ||
import com.wire.kalium.logic.framework.TestConversation | ||
import com.wire.kalium.logic.framework.TestMessage | ||
import com.wire.kalium.logic.functional.Either | ||
import io.mockative.Mock | ||
import io.mockative.given | ||
import io.mockative.mock | ||
import io.mockative.once | ||
import io.mockative.verify | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertIs | ||
|
||
class GetSearchedConversationMessagePositionUseCaseTest { | ||
|
||
@Test | ||
fun givenConversationIdAndMessageId_whenInvokingUseCase_thenShouldCallMessageRepository() = runTest { | ||
val (arrangement, getSearchedConversationMessagePosition) = Arrangement() | ||
.withRepositoryMessagePositionReturning( | ||
conversationId = CONVERSATION_ID, | ||
messageId = MESSAGE_ID, | ||
response = Either.Left(StorageFailure.DataNotFound) | ||
) | ||
.arrange() | ||
|
||
getSearchedConversationMessagePosition( | ||
conversationId = CONVERSATION_ID, | ||
messageId = MESSAGE_ID | ||
) | ||
|
||
verify(arrangement.messageRepository) | ||
.coroutine { | ||
arrangement.messageRepository.getSearchedConversationMessagePosition( | ||
conversationId = CONVERSATION_ID, | ||
messageId = MESSAGE_ID | ||
) | ||
} | ||
.wasInvoked(exactly = once) | ||
} | ||
|
||
@Test | ||
fun givenRepositoryFails_whenInvokingUseCase_thenShouldPropagateTheFailure() = runTest { | ||
val cause = StorageFailure.DataNotFound | ||
val (_, getSearchedConversationMessagePosition) = Arrangement() | ||
.withRepositoryMessagePositionReturning( | ||
conversationId = CONVERSATION_ID, | ||
messageId = MESSAGE_ID, | ||
response = Either.Left(StorageFailure.DataNotFound) | ||
) | ||
.arrange() | ||
|
||
val result = getSearchedConversationMessagePosition( | ||
conversationId = CONVERSATION_ID, | ||
messageId = MESSAGE_ID | ||
) | ||
|
||
assertIs<GetSearchedConversationMessagePositionUseCase.Result.Failure>(result) | ||
assertEquals(cause, result.cause) | ||
} | ||
|
||
@Test | ||
fun givenRepositorySucceeds_whenInvokingUseCase_thenShouldPropagateTheSuccess() = runTest { | ||
val expectedMessagePosition = 113 | ||
val (_, getSearchedConversationMessagePosition) = Arrangement() | ||
.withRepositoryMessagePositionReturning( | ||
conversationId = CONVERSATION_ID, | ||
messageId = MESSAGE_ID, | ||
response = Either.Right(expectedMessagePosition) | ||
) | ||
.arrange() | ||
|
||
val result = getSearchedConversationMessagePosition( | ||
conversationId = CONVERSATION_ID, | ||
messageId = MESSAGE_ID | ||
) | ||
|
||
assertIs<GetSearchedConversationMessagePositionUseCase.Result.Success>(result) | ||
assertEquals(expectedMessagePosition, result.position) | ||
} | ||
|
||
private inner class Arrangement { | ||
|
||
@Mock | ||
val messageRepository: MessageRepository = mock(MessageRepository::class) | ||
|
||
private val getSearchedConversationMessagePosition by lazy { | ||
GetSearchedConversationMessagePositionUseCaseImpl(messageRepository = messageRepository) | ||
} | ||
|
||
suspend fun withRepositoryMessagePositionReturning( | ||
conversationId: ConversationId, | ||
messageId: String, | ||
response: Either<StorageFailure, Int> | ||
) = apply { | ||
given(messageRepository) | ||
.coroutine { | ||
messageRepository.getSearchedConversationMessagePosition( | ||
conversationId = conversationId, | ||
messageId = messageId | ||
) | ||
} | ||
.thenReturn(response) | ||
} | ||
|
||
fun arrange() = this to getSearchedConversationMessagePosition | ||
} | ||
|
||
private companion object { | ||
const val MESSAGE_ID = TestMessage.TEST_MESSAGE_ID | ||
val MESSAGE = TestMessage.TEXT_MESSAGE | ||
val CONVERSATION_ID = TestConversation.ID | ||
} | ||
} |
Oops, something went wrong.