mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-05 09:52:13 +00:00
SES-1156 - Ban and delete functionality fix (#1428)
* WIP * Investigation in progress * End of day push * WIP * Fixes #1416 * Cleanup * Added code to remove zombie messages caught in limbo during a ban & delete - still chock full o' debug while finding root cause * Root cause debug WIP * Push prior to cleanup * Cleaned up for PR * fix: mms delete, remove unnecessary values from sms * Addressed PR feedback * fix: fix unit tests * Added '.run' folder with test setup * Update README.md Test commit for CI * Re-added accidentally removed closing brace --------- Co-authored-by: alansley <aclansley@gmail.com> Co-authored-by: Al Lansley <alansley@users.noreply.github.com> Co-authored-by: 0x330a <92654767+0x330a@users.noreply.github.com>
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
package org.thoughtcrime.securesms
|
||||
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Rule
|
||||
import org.session.libsignal.utilities.Log
|
||||
|
||||
open class BaseViewModelTest: BaseCoroutineTest() {
|
||||
|
||||
companion object {
|
||||
@BeforeClass
|
||||
@JvmStatic
|
||||
fun setupLogger() {
|
||||
Log.initialize(NoOpLogger)
|
||||
}
|
||||
}
|
||||
|
||||
@get:Rule
|
||||
var instantExecutorRule = InstantTaskExecutorRule()
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ import kotlin.time.Duration.Companion.minutes
|
||||
private const val THREAD_ID = 1L
|
||||
private const val LOCAL_NUMBER = "05---local---address"
|
||||
private val LOCAL_ADDRESS = Address.fromSerialized(LOCAL_NUMBER)
|
||||
private const val GROUP_NUMBER = "${GroupUtil.OPEN_GROUP_PREFIX}4133"
|
||||
private const val GROUP_NUMBER = "${GroupUtil.COMMUNITY_PREFIX}4133"
|
||||
private val GROUP_ADDRESS = Address.fromSerialized(GROUP_NUMBER)
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
|
||||
@@ -3,12 +3,14 @@ package org.thoughtcrime.securesms.conversation.v2
|
||||
import com.goterl.lazysodium.utils.KeyPair
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.hamcrest.CoreMatchers.endsWith
|
||||
import org.hamcrest.CoreMatchers.equalTo
|
||||
import org.hamcrest.CoreMatchers.notNullValue
|
||||
import org.hamcrest.CoreMatchers.nullValue
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.anyLong
|
||||
@@ -18,7 +20,9 @@ import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.whenever
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.session.libsignal.utilities.Log
|
||||
import org.thoughtcrime.securesms.BaseViewModelTest
|
||||
import org.thoughtcrime.securesms.NoOpLogger
|
||||
import org.thoughtcrime.securesms.database.Storage
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.repository.ConversationRepository
|
||||
@@ -32,6 +36,7 @@ class ConversationViewModelTest: BaseViewModelTest() {
|
||||
private val threadId = 123L
|
||||
private val edKeyPair = mock<KeyPair>()
|
||||
private lateinit var recipient: Recipient
|
||||
private lateinit var messageRecord: MessageRecord
|
||||
|
||||
private val viewModel: ConversationViewModel by lazy {
|
||||
ConversationViewModel(threadId, edKeyPair, repository, storage)
|
||||
@@ -40,6 +45,9 @@ class ConversationViewModelTest: BaseViewModelTest() {
|
||||
@Before
|
||||
fun setUp() {
|
||||
recipient = mock()
|
||||
messageRecord = mock { record ->
|
||||
whenever(record.individualRecipient).thenReturn(recipient)
|
||||
}
|
||||
whenever(repository.maybeGetRecipientForThreadId(anyLong())).thenReturn(recipient)
|
||||
whenever(repository.recipientUpdateFlow(anyLong())).thenReturn(emptyFlow())
|
||||
}
|
||||
@@ -144,7 +152,7 @@ class ConversationViewModelTest: BaseViewModelTest() {
|
||||
val error = Throwable()
|
||||
whenever(repository.banAndDeleteAll(anyLong(), any())).thenReturn(ResultOf.Failure(error))
|
||||
|
||||
viewModel.banAndDeleteAll(recipient)
|
||||
viewModel.banAndDeleteAll(messageRecord)
|
||||
|
||||
assertThat(viewModel.uiState.first().uiMessages.first().message, endsWith("$error"))
|
||||
}
|
||||
@@ -153,7 +161,7 @@ class ConversationViewModelTest: BaseViewModelTest() {
|
||||
fun `should emit a message on ban user and delete all success`() = runBlockingTest {
|
||||
whenever(repository.banAndDeleteAll(anyLong(), any())).thenReturn(ResultOf.Success(Unit))
|
||||
|
||||
viewModel.banAndDeleteAll(recipient)
|
||||
viewModel.banAndDeleteAll(messageRecord)
|
||||
|
||||
assertThat(
|
||||
viewModel.uiState.first().uiMessages.first().message,
|
||||
@@ -189,7 +197,7 @@ class ConversationViewModelTest: BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `open group recipient should have no blinded recipient`() {
|
||||
whenever(recipient.isOpenGroupRecipient).thenReturn(true)
|
||||
whenever(recipient.isCommunityRecipient).thenReturn(true)
|
||||
whenever(recipient.isOpenGroupOutboxRecipient).thenReturn(false)
|
||||
whenever(recipient.isOpenGroupInboxRecipient).thenReturn(false)
|
||||
assertThat(viewModel.blindedRecipient, nullValue())
|
||||
|
||||
Reference in New Issue
Block a user