Remove Rx from EventHub and TimelineCases (#3446)
* remove Rx from EventHub and TimelineCases * fix tests * fix AccountViewModel.unblockDomain * remove debug logging
This commit is contained in:
parent
66eadabd44
commit
321d17f5de
25 changed files with 264 additions and 330 deletions
|
|
@ -1,12 +1,15 @@
|
|||
package com.keylesspalace.tusky.usecase
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import app.cash.turbine.test
|
||||
import at.connyduck.calladapter.networkresult.NetworkResult
|
||||
import com.keylesspalace.tusky.appstore.EventHub
|
||||
import com.keylesspalace.tusky.appstore.PinEvent
|
||||
import com.keylesspalace.tusky.entity.Status
|
||||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
|
@ -16,7 +19,7 @@ import org.mockito.kotlin.stub
|
|||
import org.robolectric.annotation.Config
|
||||
import retrofit2.HttpException
|
||||
import retrofit2.Response
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
|
||||
@Config(sdk = [28])
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
|
|
@ -38,21 +41,21 @@ class TimelineCasesTest {
|
|||
@Test
|
||||
fun `pin success emits PinEvent`() {
|
||||
api.stub {
|
||||
onBlocking { pinStatus(statusId) } doReturn Single.just(mockStatus(pinned = true))
|
||||
onBlocking { pinStatus(statusId) } doReturn NetworkResult.success(mockStatus(pinned = true))
|
||||
}
|
||||
|
||||
val events = eventHub.events.test()
|
||||
timelineCases.pin(statusId, true)
|
||||
.test()
|
||||
.assertComplete()
|
||||
|
||||
events.assertValue(PinEvent(statusId, true))
|
||||
runBlocking {
|
||||
eventHub.events.test {
|
||||
timelineCases.pin(statusId, true)
|
||||
assertEquals(PinEvent(statusId, true), awaitItem())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `pin failure with server error throws TimelineError with server message`() {
|
||||
api.stub {
|
||||
onBlocking { pinStatus(statusId) } doReturn Single.error(
|
||||
onBlocking { pinStatus(statusId) } doReturn NetworkResult.failure(
|
||||
HttpException(
|
||||
Response.error<Status>(
|
||||
422,
|
||||
|
|
@ -61,9 +64,12 @@ class TimelineCasesTest {
|
|||
)
|
||||
)
|
||||
}
|
||||
timelineCases.pin(statusId, true)
|
||||
.test()
|
||||
.assertError { it.message == "Validation Failed: You have already pinned the maximum number of toots" }
|
||||
runBlocking {
|
||||
assertEquals(
|
||||
"Validation Failed: You have already pinned the maximum number of toots",
|
||||
timelineCases.pin(statusId, true).exceptionOrNull()?.message
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun mockStatus(pinned: Boolean = false): Status {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue