refactor(live): 온에어 접근 가드를 공통화한다

This commit is contained in:
2026-07-14 20:45:29 +09:00
parent 6973816b8c
commit ddc949f9d9
2 changed files with 50 additions and 76 deletions
@@ -7,6 +7,7 @@ import kr.co.vividnext.sodalive.v2.live.onair.model.canEnterHomeOnAirLiveRoom
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.io.File
class HomeOnAirLiveEntryPolicyTest {
@@ -25,6 +26,27 @@ class HomeOnAirLiveEntryPolicyTest {
assertFalse(canEnterHomeOnAirLiveRoom(roomDetail(channelName = " ")))
}
@Test
fun `라이브 입장은 로그인 상세 조회 성인 가드 기존 입장 순서를 유지한다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/live/onair/HomeOnAirLiveActivity.kt"
).readText()
val entrySource = sourceSection(
source = source,
startMarker = "private fun enterLiveRoom(roomId: Long) {",
endMarker = "private fun enterLiveRoom(roomId: Long, roomDetail: GetRoomDetailResponse)"
)
val loginGuard = "ensureV2Access(AccessRequirement.Login)"
val roomDetailQuery = "liveViewModel.getRoomDetail(roomId) { roomDetail ->"
val adultGuard = "ensureV2Access(AccessRequirement.forAdultContent(roomDetail.isAdult))"
val enterRoom = "enterLiveRoom(roomId, roomDetail)"
assertBefore(entrySource, loginGuard, roomDetailQuery)
assertBefore(entrySource, roomDetailQuery, adultGuard)
assertBefore(entrySource, adultGuard, enterRoom)
assertFalse(source.contains("private fun ensureLoginAndAdultAuth"))
}
private fun roomDetail(channelName: String?) = GetRoomDetailResponse(
roomId = 1L,
price = 0,
@@ -55,4 +77,28 @@ class HomeOnAirLiveEntryPolicyTest {
),
participatingUsers = emptyList()
)
private fun sourceSection(source: String, startMarker: String, endMarker: String): String {
val start = source.indexOf(startMarker)
val end = source.indexOf(endMarker, start)
assertTrue("start marker not found: $startMarker", start >= 0)
assertTrue("end marker not found after: $startMarker", end > start)
return source.substring(start, end)
}
private fun assertBefore(source: String, expectedBefore: String, expectedAfter: String) {
val beforeIndex = source.indexOf(expectedBefore)
val afterIndex = source.indexOf(expectedAfter, beforeIndex)
assertTrue("missing source: $expectedBefore", beforeIndex >= 0)
assertTrue("missing source after $expectedBefore: $expectedAfter", afterIndex > beforeIndex)
}
private fun projectFile(relativePath: String): File {
val candidates = listOf(File(relativePath), File("../$relativePath"))
return candidates.firstOrNull { it.exists() }
?: error("Project file not found: $relativePath")
}
}