feat(creator): 채널 후원 요청을 연결한다
This commit is contained in:
@@ -269,6 +269,73 @@ class CreatorChannelHomeViewModelTest {
|
||||
assertEquals(null, toastEvent?.consume())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `채널 후원 성공은 기존 후원 API를 호출하고 홈을 다시 로드한다`() {
|
||||
whenever(repository.getHome(100L, "Bearer test-token")).thenReturn(Single.just(ApiResponse(true, response(), null)))
|
||||
whenever(repository.postChannelDonation(100L, 50, true, "응원", "Bearer test-token")).thenReturn(
|
||||
Single.just(ApiResponse(true, Any(), null))
|
||||
)
|
||||
SharedPreferenceManager.can = 200
|
||||
viewModel.loadHome(100L)
|
||||
|
||||
viewModel.postChannelDonation(can = 50, isSecret = true, message = "응원")
|
||||
|
||||
verify(repository).postChannelDonation(100L, 50, true, "응원", "Bearer test-token")
|
||||
verify(repository, times(2)).getHome(100L, "Bearer test-token")
|
||||
assertEquals(150, SharedPreferenceManager.can)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `채널 후원 성공 시 보유 can보다 큰 금액 차감은 0으로 보정한다`() {
|
||||
whenever(repository.getHome(100L, "Bearer test-token")).thenReturn(Single.just(ApiResponse(true, response(), null)))
|
||||
whenever(repository.postChannelDonation(100L, 50, true, "응원", "Bearer test-token")).thenReturn(
|
||||
Single.just(ApiResponse(true, Any(), null))
|
||||
)
|
||||
SharedPreferenceManager.can = 30
|
||||
viewModel.loadHome(100L)
|
||||
|
||||
viewModel.postChannelDonation(can = 50, isSecret = true, message = "응원")
|
||||
|
||||
assertEquals(0, SharedPreferenceManager.can)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `채널 후원 진행 중 중복 요청은 무시한다`() {
|
||||
val pending = SingleSubject.create<ApiResponse<Any>>()
|
||||
whenever(repository.getHome(100L, "Bearer test-token")).thenReturn(Single.just(ApiResponse(true, response(), null)))
|
||||
whenever(repository.postChannelDonation(100L, 50, true, "응원", "Bearer test-token")).thenReturn(pending)
|
||||
viewModel.loadHome(100L)
|
||||
|
||||
viewModel.postChannelDonation(can = 50, isSecret = true, message = "응원")
|
||||
viewModel.postChannelDonation(can = 50, isSecret = true, message = "응원")
|
||||
|
||||
verify(repository, times(1)).postChannelDonation(100L, 50, true, "응원", "Bearer test-token")
|
||||
pending.onSuccess(ApiResponse(true, Any(), null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `채널 후원은 홈 content가 없으면 API를 호출하지 않는다`() {
|
||||
viewModel.postChannelDonation(can = 50, isSecret = false, message = "응원")
|
||||
|
||||
verify(repository, never()).postChannelDonation(any(), any(), any(), any(), any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `채널 후원 실패는 홈을 다시 로드하지 않고 unknown toast를 emit한다`() {
|
||||
whenever(repository.getHome(100L, "Bearer test-token")).thenReturn(Single.just(ApiResponse(true, response(), null)))
|
||||
whenever(repository.postChannelDonation(100L, 50, false, "응원", "Bearer test-token")).thenReturn(
|
||||
Single.just(ApiResponse(false, null, "failed"))
|
||||
)
|
||||
viewModel.loadHome(100L)
|
||||
|
||||
viewModel.postChannelDonation(can = 50, isSecret = false, message = "응원")
|
||||
|
||||
verify(repository).postChannelDonation(100L, 50, false, "응원", "Bearer test-token")
|
||||
verify(repository, times(1)).getHome(100L, "Bearer test-token")
|
||||
val toastEvent = viewModel.toastLiveData.requireValue()
|
||||
assertEquals(R.string.common_error_unknown, toastEvent?.consume()?.resId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `차단 성공은 block API를 호출하고 차단 완료 토스트를 emit한다`() {
|
||||
whenever(repository.getHome(100L, "Bearer test-token")).thenReturn(Single.just(ApiResponse(true, response(), null)))
|
||||
|
||||
Reference in New Issue
Block a user