feat(live): 온에어 라이브 매핑을 추가한다
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package kr.co.vividnext.sodalive.v2.live.onair
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.live.onair.data.HomeOnAirLivePageResponse
|
||||
import kr.co.vividnext.sodalive.v2.live.onair.data.HomeOnAirLiveResponse
|
||||
import kr.co.vividnext.sodalive.v2.live.onair.model.HomeOnAirLivePriceUiModel
|
||||
import kr.co.vividnext.sodalive.v2.live.onair.model.toUiState
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.util.TimeZone
|
||||
|
||||
class HomeOnAirLiveMapperTest {
|
||||
|
||||
@Test
|
||||
fun `beginDateTimeUtc를 디바이스 Timezone 기준 LIVE HH mm으로 변환한다`() {
|
||||
val state = pageResponse(
|
||||
items = listOf(live(beginDateTimeUtc = "2026-06-26T12:34:00Z"))
|
||||
).toUiState(TimeZone.getTimeZone("Asia/Seoul"))
|
||||
|
||||
assertEquals("LIVE 21:34", state.items.single().liveTimeText)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `price가 0보다 크면 유료 가격 표시 모델로 매핑한다`() {
|
||||
val price = pageResponse(items = listOf(live(price = 150))).toUiState().items.single().price
|
||||
|
||||
assertTrue(price is HomeOnAirLivePriceUiModel.Paid)
|
||||
assertEquals(150, (price as HomeOnAirLivePriceUiModel.Paid).amount)
|
||||
assertEquals("150", price.amountText)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `price가 0이면 무료 표시 모델로 매핑한다`() {
|
||||
val price = pageResponse(items = listOf(live(price = 0))).toUiState().items.single().price
|
||||
|
||||
assertTrue(price is HomeOnAirLivePriceUiModel.Free)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `page 응답의 metadata와 items를 UI state로 유지한다`() {
|
||||
val state = pageResponse(
|
||||
page = 2,
|
||||
size = 20,
|
||||
hasNext = true,
|
||||
items = listOf(live(roomId = 10L), live(roomId = 11L))
|
||||
).toUiState()
|
||||
|
||||
assertEquals(2, state.page)
|
||||
assertEquals(20, state.size)
|
||||
assertTrue(state.hasNext)
|
||||
assertEquals(listOf(10L, 11L), state.items.map { it.roomId })
|
||||
}
|
||||
|
||||
private fun pageResponse(
|
||||
items: List<HomeOnAirLiveResponse> = listOf(live()),
|
||||
page: Int = 0,
|
||||
size: Int = 20,
|
||||
hasNext: Boolean = false
|
||||
) = HomeOnAirLivePageResponse(
|
||||
items = items,
|
||||
page = page,
|
||||
size = size,
|
||||
hasNext = hasNext
|
||||
)
|
||||
|
||||
private fun live(
|
||||
roomId: Long = 1L,
|
||||
creatorNickname: String = "크리에이터",
|
||||
creatorProfileImage: String = "https://example.com/profile.png",
|
||||
title: String = "라이브 제목",
|
||||
price: Int = 100,
|
||||
beginDateTimeUtc: String = "2026-06-26T12:00:00Z"
|
||||
) = HomeOnAirLiveResponse(
|
||||
roomId = roomId,
|
||||
creatorNickname = creatorNickname,
|
||||
creatorProfileImage = creatorProfileImage,
|
||||
title = title,
|
||||
price = price,
|
||||
beginDateTimeUtc = beginDateTimeUtc
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user