fix(creator): 오디오 탭 theme 선택 정규화를 보정한다
This commit is contained in:
@@ -15,6 +15,7 @@ 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.audio.model.CreatorChannelAudioRateUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelAudioContentResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelRepository
|
||||
import org.junit.After
|
||||
@@ -151,6 +152,64 @@ class CreatorChannelAudioViewModelTest {
|
||||
verifyGetAudio(sort = ContentSort.POPULAR, themeId = 10L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `응답 themeId가 서버 themes에 없으면 selectedThemeId를 null로 정규화하고 후속 정렬 요청도 null로 보낸다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = 99L), null)))
|
||||
stubGetAudio(
|
||||
sort = ContentSort.POPULAR,
|
||||
themeId = null,
|
||||
response = Single.just(ApiResponse(true, audioResponse(sort = ContentSort.POPULAR, themeId = null), null))
|
||||
)
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
val initialState = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertNull(initialState.selectedThemeId)
|
||||
assertEquals(CreatorChannelAudioRateUiModel(75.0, 3, 4), initialState.rate)
|
||||
|
||||
viewModel.changeSort(ContentSort.POPULAR)
|
||||
|
||||
val sortedState = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertNull(sortedState.selectedThemeId)
|
||||
verifyGetAudio(sort = ContentSort.POPULAR, themeId = null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `선택 테마 응답 themeId가 서버 themes에 없으면 내부 selectedThemeId도 null로 정규화한다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(themeId = null), null)))
|
||||
stubGetAudio(
|
||||
themeId = 10L,
|
||||
response = Single.just(ApiResponse(true, audioResponse(themeId = 99L), null))
|
||||
)
|
||||
stubGetAudio(
|
||||
sort = ContentSort.POPULAR,
|
||||
themeId = null,
|
||||
response = Single.just(ApiResponse(true, audioResponse(sort = ContentSort.POPULAR, themeId = null), null))
|
||||
)
|
||||
whenever(
|
||||
repository.getAudio(
|
||||
100L,
|
||||
0,
|
||||
CreatorChannelAudioViewModel.DEFAULT_PAGE_SIZE,
|
||||
ContentSort.POPULAR,
|
||||
10L,
|
||||
"Bearer test-token"
|
||||
)
|
||||
).thenThrow(AssertionError("정규화 후 정렬 요청은 이전 선택 themeId를 사용하면 안 된다"))
|
||||
viewModel.loadAudio(100L, isOwner = false)
|
||||
|
||||
viewModel.changeTheme(10L)
|
||||
|
||||
val themeState = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertNull(themeState.selectedThemeId)
|
||||
|
||||
viewModel.changeSort(ContentSort.POPULAR)
|
||||
|
||||
val sortedState = viewModel.audioStateLiveData.requireValue() as CreatorChannelAudioUiState.Content
|
||||
assertNull(sortedState.selectedThemeId)
|
||||
verifyGetAudio(themeId = 10L)
|
||||
verifyGetAudio(sort = ContentSort.POPULAR, themeId = null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `같은 정렬 또는 같은 테마를 다시 선택하면 API를 재호출하지 않는다`() {
|
||||
stubGetAudio(response = Single.just(ApiResponse(true, audioResponse(), null)))
|
||||
|
||||
Reference in New Issue
Block a user