feat(creator-channel): 오디오 탭 조회 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.audio.domain
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.common.domain.ContentSort
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class CreatorChannelAudioQueryPolicyTest {
|
||||
private val policy = CreatorChannelAudioQueryPolicy()
|
||||
|
||||
@Test
|
||||
@DisplayName("오디오 탭 page 정책은 page와 size를 fallback하고 fetch limit을 계산한다")
|
||||
fun shouldFallbackPageAndSizeForAudioTab() {
|
||||
val minimumPage = policy.createPage(page = -1, size = 10)
|
||||
val maximumPage = policy.createPage(page = 2, size = 100)
|
||||
|
||||
assertEquals(0, minimumPage.page)
|
||||
assertEquals(20, minimumPage.size)
|
||||
assertEquals(0L, minimumPage.offset)
|
||||
assertEquals(21, minimumPage.fetchLimit)
|
||||
assertEquals(2, maximumPage.page)
|
||||
assertEquals(50, maximumPage.size)
|
||||
assertEquals(100L, maximumPage.offset)
|
||||
assertEquals(51, maximumPage.fetchLimit)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("오디오 탭 sort 정책은 null과 알 수 없는 값을 LATEST로 fallback한다")
|
||||
fun shouldFallbackInvalidSortToLatest() {
|
||||
assertEquals(ContentSort.LATEST, policy.resolveSort(null))
|
||||
assertEquals(ContentSort.LATEST, policy.resolveSort("UNKNOWN"))
|
||||
assertEquals(ContentSort.POPULAR, policy.resolveSort("POPULAR"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("오디오 탭 목록 정책은 요청 size만 남기고 다음 페이지 여부를 계산한다")
|
||||
fun shouldLimitItemsAndCalculateHasNext() {
|
||||
val page = policy.createPage(page = 0, size = 20)
|
||||
val fetched = (1..21).toList()
|
||||
|
||||
val items = policy.limitItems(fetched, page)
|
||||
|
||||
assertEquals((1..20).toList(), items)
|
||||
assertTrue(policy.hasNext(fetched, page))
|
||||
assertFalse(policy.hasNext((1..20).toList(), page))
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("오디오 탭 소장률은 유료 콘텐츠가 없으면 0이고 있으면 백분율로 계산한다")
|
||||
fun shouldCalculatePurchaseRate() {
|
||||
assertEquals(0.0, policy.purchaseRate(paidAudioContentCount = 0, purchasedAudioContentCount = 3))
|
||||
assertEquals(75.0, policy.purchaseRate(paidAudioContentCount = 4, purchasedAudioContentCount = 3))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user