feat(creator): 채널 라이브 탭 도메인 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.live.domain
|
||||
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class CreatorChannelLiveReplayQueryPolicyTest {
|
||||
private val policy = CreatorChannelLiveReplayQueryPolicy()
|
||||
|
||||
@Test
|
||||
@DisplayName("라이브 다시듣기 page 정책은 offset, fetch limit, items limit, hasNext를 계산한다")
|
||||
fun shouldCalculatePagePolicyForLiveReplayContents() {
|
||||
val page = policy.createPage(page = 0, size = 20)
|
||||
val fetched = (1..21).toList()
|
||||
|
||||
val items = policy.limitItems(fetched, page)
|
||||
|
||||
assertEquals(0L, page.offset)
|
||||
assertEquals(21, page.fetchLimit)
|
||||
assertEquals(20, items.size)
|
||||
assertEquals((1..20).toList(), items)
|
||||
assertTrue(policy.hasNext(fetched, page))
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("size가 50이면 fetch limit을 51로 계산한다")
|
||||
fun shouldCalculateFetchLimitWhenSizeIsMaximum() {
|
||||
val page = policy.createPage(page = 1, size = 50)
|
||||
|
||||
assertEquals(50L, page.offset)
|
||||
assertEquals(51, page.fetchLimit)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("page가 0보다 작으면 invalid request 예외를 던진다")
|
||||
fun shouldThrowInvalidRequestWhenPageIsNegative() {
|
||||
val exception = assertThrows(SodaException::class.java) {
|
||||
policy.createPage(page = -1, size = 20)
|
||||
}
|
||||
|
||||
assertEquals("common.error.invalid_request", exception.messageKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("size가 20보다 작으면 invalid request 예외를 던진다")
|
||||
fun shouldThrowInvalidRequestWhenSizeIsLessThanMinimum() {
|
||||
val exception = assertThrows(SodaException::class.java) {
|
||||
policy.createPage(page = 0, size = 19)
|
||||
}
|
||||
|
||||
assertEquals("common.error.invalid_request", exception.messageKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("size가 50보다 크면 invalid request 예외를 던진다")
|
||||
fun shouldThrowInvalidRequestWhenSizeIsGreaterThanMaximum() {
|
||||
val exception = assertThrows(SodaException::class.java) {
|
||||
policy.createPage(page = 0, size = 51)
|
||||
}
|
||||
|
||||
assertEquals("common.error.invalid_request", exception.messageKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("size가 Int 최대값이면 fetch limit overflow 전에 invalid request 예외를 던진다")
|
||||
fun shouldThrowInvalidRequestWhenSizeWouldOverflowFetchLimit() {
|
||||
val exception = assertThrows(SodaException::class.java) {
|
||||
policy.createPage(page = 0, size = Int.MAX_VALUE)
|
||||
}
|
||||
|
||||
assertEquals("common.error.invalid_request", exception.messageKey)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user