feat(creator): 오디오 탭 상태 관리를 추가한다
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.audio
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins
|
||||
import io.reactivex.rxjava3.core.Scheduler
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.plugins.RxJavaPlugins
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import io.reactivex.rxjava3.subjects.SingleSubject
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.v2.common.data.ContentSort
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.data.CreatorChannelAudioTabResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.data.CreatorChannelAudioThemeResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelAudioContentResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelRepository
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.times
|
||||
import org.mockito.kotlin.verify
|
||||
import org.mockito.kotlin.whenever
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class CreatorChannelAudioPaginationTest {
|
||||
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
private lateinit var repository: CreatorChannelRepository
|
||||
private lateinit var viewModel: CreatorChannelAudioViewModel
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
setImmediateRxSchedulers()
|
||||
SharedPreferenceManager.resetForTest()
|
||||
SharedPreferenceManager.init(context)
|
||||
SharedPreferenceManager.token = "test-token"
|
||||
repository = org.mockito.kotlin.mock()
|
||||
viewModel = CreatorChannelAudioViewModel(repository)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
RxJavaPlugins.reset()
|
||||
RxAndroidPlugins.reset()
|
||||
SharedPreferenceManager.resetForTest()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `hasNext가 true이면 다음 페이지는 마지막 성공 응답의 page plus 1로 요청하고 append한다`() {
|
||||
stubGetAudio(
|
||||
page = 0,
|
||||
response = Single.just(
|
||||
ApiResponse(true, audioResponse(page = 0, ids = listOf(1L), hasNext = true), null)
|
||||
)
|
||||
)
|
||||
stubGetAudio(
|
||||
page = 1,
|
||||
response = Single.just(
|
||||
ApiResponse(true, audioResponse(page = 1, ids = listOf(2L), hasNext = false), null)
|
||||
)
|
||||
)
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
viewModel.loadMore()
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(1, state.page)
|
||||
assertEquals(listOf(1L, 2L), state.audioContents.map { it.audioContentId })
|
||||
assertFalse(state.hasNext)
|
||||
verifyGetAudio(page = 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `다음 페이지 로딩 중 중복 load-more 요청은 막는다`() {
|
||||
val pending = SingleSubject.create<ApiResponse<CreatorChannelAudioTabResponse>>()
|
||||
stubGetAudio(
|
||||
page = 0,
|
||||
response = Single.just(
|
||||
ApiResponse(true, audioResponse(page = 0, ids = listOf(1L), hasNext = true), null)
|
||||
)
|
||||
)
|
||||
stubGetAudio(page = 1, response = pending)
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
viewModel.loadMore()
|
||||
viewModel.loadMore()
|
||||
|
||||
val loadingState = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertTrue(loadingState.isLoadingMore)
|
||||
verifyGetAudio(page = 1, times = 1)
|
||||
pending.onSuccess(
|
||||
ApiResponse(true, audioResponse(page = 1, ids = listOf(2L), hasNext = false), null)
|
||||
)
|
||||
val loadedState = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(listOf(1L, 2L), loadedState.audioContents.map { it.audioContentId })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `다음 페이지 실패는 기존 목록을 유지하고 pagination error를 표시한다`() {
|
||||
stubGetAudio(
|
||||
page = 0,
|
||||
response = Single.just(
|
||||
ApiResponse(true, audioResponse(page = 0, ids = listOf(1L), hasNext = true), null)
|
||||
)
|
||||
)
|
||||
stubGetAudio(page = 1, response = Single.just(ApiResponse(false, null, "failed")))
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
viewModel.loadMore()
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(listOf(1L), state.audioContents.map { it.audioContentId })
|
||||
assertFalse(state.isLoadingMore)
|
||||
assertEquals("failed", state.paginationErrorMessage)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `pagination error message는 표시 후 clear되어 다시 표시되지 않는다`() {
|
||||
stubGetAudio(
|
||||
page = 0,
|
||||
response = Single.just(
|
||||
ApiResponse(true, audioResponse(page = 0, ids = listOf(1L), hasNext = true), null)
|
||||
)
|
||||
)
|
||||
stubGetAudio(page = 1, response = Single.just(ApiResponse(false, null, "failed")))
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
viewModel.loadMore()
|
||||
|
||||
viewModel.consumePaginationErrorMessage()
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(null, state.paginationErrorMessage)
|
||||
assertEquals(listOf(1L), state.audioContents.map { it.audioContentId })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `이전 load-more 응답은 이후 정렬 변경 목록에 append되지 않는다`() {
|
||||
val nextPagePending = SingleSubject.create<ApiResponse<CreatorChannelAudioTabResponse>>()
|
||||
stubGetAudio(
|
||||
page = 0,
|
||||
response = Single.just(
|
||||
ApiResponse(true, audioResponse(page = 0, ids = listOf(1L), hasNext = true), null)
|
||||
)
|
||||
)
|
||||
stubGetAudio(page = 1, response = nextPagePending)
|
||||
stubGetAudio(
|
||||
page = 0,
|
||||
sort = ContentSort.POPULAR,
|
||||
response = Single.just(
|
||||
ApiResponse(
|
||||
true,
|
||||
audioResponse(page = 0, sort = ContentSort.POPULAR, ids = listOf(10L), hasNext = false),
|
||||
null
|
||||
)
|
||||
)
|
||||
)
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
viewModel.loadMore()
|
||||
viewModel.changeSort(ContentSort.POPULAR)
|
||||
nextPagePending.onSuccess(
|
||||
ApiResponse(true, audioResponse(page = 1, ids = listOf(2L), hasNext = false), null)
|
||||
)
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(ContentSort.POPULAR, state.selectedSort)
|
||||
assertEquals(listOf(10L), state.audioContents.map { it.audioContentId })
|
||||
}
|
||||
|
||||
private fun stubGetAudio(
|
||||
page: Int,
|
||||
sort: ContentSort = ContentSort.LATEST,
|
||||
themeId: Long? = null,
|
||||
response: Single<ApiResponse<CreatorChannelAudioTabResponse>>
|
||||
) {
|
||||
whenever(
|
||||
repository.getAudio(
|
||||
100L,
|
||||
page,
|
||||
CreatorChannelAudioViewModel.DEFAULT_PAGE_SIZE,
|
||||
sort,
|
||||
themeId,
|
||||
"Bearer test-token"
|
||||
)
|
||||
).thenReturn(response)
|
||||
}
|
||||
|
||||
private fun verifyGetAudio(
|
||||
page: Int,
|
||||
sort: ContentSort = ContentSort.LATEST,
|
||||
themeId: Long? = null,
|
||||
times: Int? = null
|
||||
) {
|
||||
val verification = times?.let { verify(repository, times(it)) } ?: verify(repository)
|
||||
verification.getAudio(
|
||||
100L,
|
||||
page,
|
||||
CreatorChannelAudioViewModel.DEFAULT_PAGE_SIZE,
|
||||
sort,
|
||||
themeId,
|
||||
"Bearer test-token"
|
||||
)
|
||||
}
|
||||
|
||||
private fun setImmediateRxSchedulers() {
|
||||
val trampoline = { _: Scheduler -> Schedulers.trampoline() }
|
||||
RxJavaPlugins.setIoSchedulerHandler(trampoline)
|
||||
RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
|
||||
RxAndroidPlugins.setMainThreadSchedulerHandler { Schedulers.trampoline() }
|
||||
}
|
||||
|
||||
private fun audioResponse(
|
||||
page: Int,
|
||||
sort: ContentSort = ContentSort.LATEST,
|
||||
ids: List<Long>,
|
||||
hasNext: Boolean
|
||||
) = CreatorChannelAudioTabResponse(
|
||||
audioContentCount = ids.size,
|
||||
themes = listOf(CreatorChannelAudioThemeResponse(themeId = 10L, themeName = "ASMR")),
|
||||
themeId = null,
|
||||
purchasedAudioContentRate = 75.0,
|
||||
purchasedAudioContentCount = 3,
|
||||
paidAudioContentCount = 4,
|
||||
audioContents = ids.map { audioContent(it) },
|
||||
sort = sort,
|
||||
page = page,
|
||||
size = CreatorChannelAudioViewModel.DEFAULT_PAGE_SIZE,
|
||||
hasNext = hasNext
|
||||
)
|
||||
|
||||
private fun audioContent(id: Long) = CreatorChannelAudioContentResponse(
|
||||
audioContentId = id,
|
||||
title = "오디오 $id",
|
||||
duration = "01:00",
|
||||
imageUrl = null,
|
||||
price = 0,
|
||||
isPointAvailable = true,
|
||||
isFirstContent = false,
|
||||
seriesName = null,
|
||||
isOriginalSeries = null
|
||||
)
|
||||
|
||||
private fun <T> LiveData<T>.requireValue(): T? {
|
||||
var value: T? = null
|
||||
val observer = Observer<T> { value = it }
|
||||
observeForever(observer)
|
||||
removeObserver(observer)
|
||||
return value
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.audio
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins
|
||||
import io.reactivex.rxjava3.core.Scheduler
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.plugins.RxJavaPlugins
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.v2.common.data.ContentSort
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.data.CreatorChannelAudioTabResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.data.CreatorChannelAudioThemeResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelAudioContentResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelRepository
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.never
|
||||
import org.mockito.kotlin.times
|
||||
import org.mockito.kotlin.verify
|
||||
import org.mockito.kotlin.whenever
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class CreatorChannelAudioViewModelTest {
|
||||
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
private lateinit var repository: CreatorChannelRepository
|
||||
private lateinit var viewModel: CreatorChannelAudioViewModel
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
setImmediateRxSchedulers()
|
||||
SharedPreferenceManager.resetForTest()
|
||||
SharedPreferenceManager.init(context)
|
||||
SharedPreferenceManager.token = "test-token"
|
||||
repository = org.mockito.kotlin.mock()
|
||||
viewModel = CreatorChannelAudioViewModel(repository)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
RxJavaPlugins.reset()
|
||||
RxAndroidPlugins.reset()
|
||||
SharedPreferenceManager.resetForTest()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `최초 로드는 page 0 size 20 최신순 themeId null로 오디오 API를 호출하고 Content를 emit한다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(), null)))
|
||||
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(ContentSort.LATEST, state.selectedSort)
|
||||
assertNull(state.selectedThemeId)
|
||||
assertEquals(0, state.page)
|
||||
assertEquals(listOf(1L), state.audioContents.map { it.audioContentId })
|
||||
verifyGetAudio(themeId = null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `응답 themes 앞에 전체 tab을 추가하고 themeId null이면 전체를 선택한다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = null), null)))
|
||||
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(listOf(null, 10L), state.themes.map { it.themeId })
|
||||
assertEquals("전체", state.themes.first().title)
|
||||
assertTrue(state.themes.first().isSelected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `테마 선택은 page 0과 현재 sort와 선택 themeId로 재조회한다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = null, ids = listOf(1L)), null)))
|
||||
stubGetAudio(
|
||||
themeId = 10L,
|
||||
response = Single.just(ApiResponse(true, audioResponse(themeId = 10L, ids = listOf(2L)), null))
|
||||
)
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
viewModel.changeTheme(10L)
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(10L, state.selectedThemeId)
|
||||
assertEquals(listOf(2L), state.audioContents.map { it.audioContentId })
|
||||
verifyGetAudio(themeId = 10L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `전체 선택은 themeId null로 재조회한다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = null), null)))
|
||||
stubGetAudio(
|
||||
themeId = 10L,
|
||||
response = Single.just(ApiResponse(true, audioResponse(themeId = 10L), null))
|
||||
)
|
||||
whenever(
|
||||
repository.getAudio(
|
||||
100L,
|
||||
0,
|
||||
CreatorChannelAudioViewModel.DEFAULT_PAGE_SIZE,
|
||||
ContentSort.LATEST,
|
||||
null,
|
||||
"Bearer test-token"
|
||||
)
|
||||
).thenReturn(
|
||||
Single.just(ApiResponse(true, audioResponse(themeId = null), null)),
|
||||
Single.just(ApiResponse(true, audioResponse(themeId = null, ids = listOf(3L)), null))
|
||||
)
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
viewModel.changeTheme(10L)
|
||||
|
||||
viewModel.changeTheme(null)
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertNull(state.selectedThemeId)
|
||||
assertEquals(listOf(3L), state.audioContents.map { it.audioContentId })
|
||||
verifyGetAudio(themeId = null, times = 2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `정렬 변경은 page 0과 선택 themeId를 유지해 재조회한다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = null), null)))
|
||||
stubGetAudio(themeId = 10L, response = Single.just(ApiResponse(true, audioResponse(themeId = 10L), null)))
|
||||
stubGetAudio(
|
||||
sort = ContentSort.POPULAR,
|
||||
themeId = 10L,
|
||||
response = Single.just(ApiResponse(true, audioResponse(sort = ContentSort.POPULAR, themeId = 10L), null))
|
||||
)
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
viewModel.changeTheme(10L)
|
||||
|
||||
viewModel.changeSort(ContentSort.POPULAR)
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(ContentSort.POPULAR, state.selectedSort)
|
||||
assertEquals(10L, state.selectedThemeId)
|
||||
verifyGetAudio(sort = ContentSort.POPULAR, themeId = 10L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `같은 정렬 또는 같은 테마를 다시 선택하면 API를 재호출하지 않는다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(), null)))
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
viewModel.changeSort(ContentSort.LATEST)
|
||||
viewModel.changeTheme(null)
|
||||
|
||||
verifyGetAudio(themeId = null, times = 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `duration null item은 제외하고 표시 가능한 item이 없으면 Empty를 emit한다`() {
|
||||
stubGetAudio(
|
||||
response = Single.just(ApiResponse(true, audioResponse(ids = listOf(1L), nullDurationIds = setOf(1L)), null))
|
||||
)
|
||||
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
assertTrue(viewModel.audioStateLiveData.requireValue() is CreatorChannelAudioUiState.Empty)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `audioContentCount가 0이면 표시 가능한 item이 있어도 Empty를 emit한다`() {
|
||||
stubGetAudio(
|
||||
response = Single.just(ApiResponse(true, audioResponse(audioContentCount = 0, ids = listOf(1L)), null))
|
||||
)
|
||||
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
assertTrue(viewModel.audioStateLiveData.requireValue() is CreatorChannelAudioUiState.Empty)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `소장률은 내 채널이 아니고 전체 테마일 때만 생성된다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = null), null)))
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
val guestState = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertEquals(CreatorChannelAudioRateUiModel(75.0, 3, 4), guestState.rate)
|
||||
|
||||
viewModel = CreatorChannelAudioViewModel(repository)
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = null), null)))
|
||||
viewModel.loadAudio(100L, isOwner = true)
|
||||
|
||||
val ownerState = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertNull(ownerState.rate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `특정 테마 선택 상태에서는 소장률이 null이다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = null), null)))
|
||||
stubGetAudio(themeId = 10L, response = Single.just(ApiResponse(true, audioResponse(themeId = 10L), null)))
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
viewModel.changeTheme(10L)
|
||||
|
||||
val state = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertNull(state.rate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `creatorId가 0 이하이면 오디오 API를 호출하지 않는다`() {
|
||||
viewModel.loadAudio(0L, isOwner = false)
|
||||
|
||||
verify(repository, never()).getAudio(any(), any(), any(), any(), any(), any())
|
||||
}
|
||||
|
||||
private fun stubGetAudio(
|
||||
page: Int = 0,
|
||||
sort: ContentSort = ContentSort.LATEST,
|
||||
themeId: Long? = null,
|
||||
response: Single<ApiResponse<CreatorChannelAudioTabResponse>>
|
||||
) {
|
||||
whenever(
|
||||
repository.getAudio(
|
||||
100L,
|
||||
page,
|
||||
CreatorChannelAudioViewModel.DEFAULT_PAGE_SIZE,
|
||||
sort,
|
||||
themeId,
|
||||
"Bearer test-token"
|
||||
)
|
||||
).thenReturn(response)
|
||||
}
|
||||
|
||||
private fun verifyGetAudio(
|
||||
page: Int = 0,
|
||||
sort: ContentSort = ContentSort.LATEST,
|
||||
themeId: Long?,
|
||||
times: Int? = null
|
||||
) {
|
||||
val verification = times?.let { verify(repository, times(it)) } ?: verify(repository)
|
||||
verification.getAudio(
|
||||
100L,
|
||||
page,
|
||||
CreatorChannelAudioViewModel.DEFAULT_PAGE_SIZE,
|
||||
sort,
|
||||
themeId,
|
||||
"Bearer test-token"
|
||||
)
|
||||
}
|
||||
|
||||
private fun setImmediateRxSchedulers() {
|
||||
val trampoline = { _: Scheduler -> Schedulers.trampoline() }
|
||||
RxJavaPlugins.setIoSchedulerHandler(trampoline)
|
||||
RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
|
||||
RxAndroidPlugins.setMainThreadSchedulerHandler { Schedulers.trampoline() }
|
||||
}
|
||||
|
||||
private fun audioResponse(
|
||||
page: Int = 0,
|
||||
sort: ContentSort = ContentSort.LATEST,
|
||||
themeId: Long? = null,
|
||||
audioContentCount: Int? = null,
|
||||
ids: List<Long> = listOf(1L),
|
||||
nullDurationIds: Set<Long> = emptySet(),
|
||||
hasNext: Boolean = false
|
||||
) = CreatorChannelAudioTabResponse(
|
||||
audioContentCount = audioContentCount ?: ids.size,
|
||||
themes = listOf(CreatorChannelAudioThemeResponse(themeId = 10L, themeName = "ASMR")),
|
||||
themeId = themeId,
|
||||
purchasedAudioContentRate = 75.0,
|
||||
purchasedAudioContentCount = 3,
|
||||
paidAudioContentCount = 4,
|
||||
audioContents = ids.map { audioContent(it, duration = if (it in nullDurationIds) null else "01:00") },
|
||||
sort = sort,
|
||||
page = page,
|
||||
size = CreatorChannelAudioViewModel.DEFAULT_PAGE_SIZE,
|
||||
hasNext = hasNext
|
||||
)
|
||||
|
||||
private fun audioContent(id: Long, duration: String?) = CreatorChannelAudioContentResponse(
|
||||
audioContentId = id,
|
||||
title = "오디오 $id",
|
||||
duration = duration,
|
||||
imageUrl = null,
|
||||
price = 0,
|
||||
isPointAvailable = true,
|
||||
isFirstContent = false,
|
||||
seriesName = null,
|
||||
isOriginalSeries = null
|
||||
)
|
||||
|
||||
private fun <T> LiveData<T>.requireValue(): T? {
|
||||
var value: T? = null
|
||||
val observer = Observer<T> { value = it }
|
||||
observeForever(observer)
|
||||
removeObserver(observer)
|
||||
return value
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user