feat(live): 입장 정책 모델을 추가한다
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.live.action
|
||||||
|
|
||||||
|
sealed interface LiveEntryDecision {
|
||||||
|
data object ShowDetail : LiveEntryDecision
|
||||||
|
|
||||||
|
data object Enter : LiveEntryDecision
|
||||||
|
|
||||||
|
data class RequestPassword(val can: Int) : LiveEntryDecision
|
||||||
|
|
||||||
|
data object RequestPayment : LiveEntryDecision
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.live.action
|
||||||
|
|
||||||
|
data class LiveEntryContext(
|
||||||
|
val channelName: String?,
|
||||||
|
val managerId: Long,
|
||||||
|
val currentUserId: Long,
|
||||||
|
val price: Int,
|
||||||
|
val isPaid: Boolean,
|
||||||
|
val isPrivateRoom: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
object LiveEntryPolicy {
|
||||||
|
fun decide(context: LiveEntryContext): LiveEntryDecision = with(context) {
|
||||||
|
when {
|
||||||
|
channelName.isNullOrBlank() -> LiveEntryDecision.ShowDetail
|
||||||
|
managerId == currentUserId -> LiveEntryDecision.Enter
|
||||||
|
(price == 0 || isPaid) && isPrivateRoom -> LiveEntryDecision.RequestPassword(can = 0)
|
||||||
|
price == 0 || isPaid -> LiveEntryDecision.Enter
|
||||||
|
isPrivateRoom -> LiveEntryDecision.RequestPassword(can = price)
|
||||||
|
else -> LiveEntryDecision.RequestPayment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.live.action
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class LiveEntryPolicyTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `channel이 없으면 라이브 상세를 표시한다`() {
|
||||||
|
assertEquals(LiveEntryDecision.ShowDetail, decide(channelName = null))
|
||||||
|
assertEquals(LiveEntryDecision.ShowDetail, decide(channelName = " "))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `channel이 없으면 본인 manager여도 라이브 상세를 우선 표시한다`() {
|
||||||
|
assertEquals(
|
||||||
|
LiveEntryDecision.ShowDetail,
|
||||||
|
decide(channelName = null, managerId = 7L, currentUserId = 7L)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `관리자는 가격과 비밀번호보다 우선해 바로 입장한다`() {
|
||||||
|
assertEquals(
|
||||||
|
LiveEntryDecision.Enter,
|
||||||
|
decide(managerId = 7L, currentUserId = 7L, price = 100, isPrivateRoom = true)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `무료 또는 결제 완료 공개방은 바로 입장한다`() {
|
||||||
|
assertEquals(LiveEntryDecision.Enter, decide(price = 0))
|
||||||
|
assertEquals(LiveEntryDecision.Enter, decide(price = 100, isPaid = true))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `무료 또는 결제 완료 비밀번호방은 결제액 없이 비밀번호를 요청한다`() {
|
||||||
|
assertEquals(
|
||||||
|
LiveEntryDecision.RequestPassword(can = 0),
|
||||||
|
decide(price = 0, isPrivateRoom = true)
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
LiveEntryDecision.RequestPassword(can = 0),
|
||||||
|
decide(price = 100, isPaid = true, isPrivateRoom = true)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `미결제 유료 비밀번호방은 가격과 함께 비밀번호를 요청한다`() {
|
||||||
|
assertEquals(
|
||||||
|
LiveEntryDecision.RequestPassword(can = 100),
|
||||||
|
decide(price = 100, isPrivateRoom = true)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `미결제 유료 공개방은 결제를 요청한다`() {
|
||||||
|
assertEquals(LiveEntryDecision.RequestPayment, decide(price = 100))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun decide(
|
||||||
|
channelName: String? = "channel",
|
||||||
|
managerId: Long = 2L,
|
||||||
|
currentUserId: Long = 1L,
|
||||||
|
price: Int = 0,
|
||||||
|
isPaid: Boolean = false,
|
||||||
|
isPrivateRoom: Boolean = false
|
||||||
|
): LiveEntryDecision = LiveEntryPolicy.decide(
|
||||||
|
LiveEntryContext(
|
||||||
|
channelName = channelName,
|
||||||
|
managerId = managerId,
|
||||||
|
currentUserId = currentUserId,
|
||||||
|
price = price,
|
||||||
|
isPaid = isPaid,
|
||||||
|
isPrivateRoom = isPrivateRoom
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user