feat(creator-channel): 커뮤니티 탭 응답 조립을 추가한다

This commit is contained in:
2026-06-22 00:01:45 +09:00
parent bd4e865f2e
commit e0e6b34d21
4 changed files with 242 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
package kr.co.vividnext.sodalive.v2.api.creator.channel.community.application
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.member.MemberRole
import kr.co.vividnext.sodalive.v2.api.creator.channel.community.dto.CreatorChannelCommunityTabResponse
import kr.co.vividnext.sodalive.v2.creator.channel.community.application.CreatorChannelCommunityQueryService
import kr.co.vividnext.sodalive.v2.creator.channel.community.domain.CreatorChannelCommunityPost
import kr.co.vividnext.sodalive.v2.creator.channel.community.domain.CreatorChannelCommunityTab
import kr.co.vividnext.sodalive.v2.creator.channel.live.domain.CreatorChannelPage
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import java.time.LocalDateTime
class CreatorChannelCommunityFacadeTest {
@Test
@DisplayName("커뮤니티 탭 응답 DTO는 domain tab 값을 공개 응답 필드로 그대로 매핑한다")
fun shouldMapCommunityTabDomainToPublicResponse() {
val response = CreatorChannelCommunityTabResponse.from(createTab())
assertEquals(2, response.communityPostCount)
assertEquals(101L, response.communityPosts.first().postId)
assertEquals(1L, response.communityPosts.first().creatorId)
assertEquals("creator", response.communityPosts.first().creatorNickname)
assertEquals("https://cdn.test/profile.png", response.communityPosts.first().creatorProfileUrl)
assertEquals("2026-06-21T03:30:00Z", response.communityPosts.first().createdAtUtc)
assertEquals("paid content", response.communityPosts.first().content)
assertEquals("https://cdn.test/image.png", response.communityPosts.first().imageUrl)
assertEquals("https://signed.test/audio", response.communityPosts.first().audioUrl)
assertEquals(100, response.communityPosts.first().price)
assertTrue(response.communityPosts.first().isCommentAvailable)
assertTrue(response.communityPosts.first().existOrdered)
assertEquals(7, response.communityPosts.first().likeCount)
assertEquals(3, response.communityPosts.first().commentCount)
assertTrue(response.communityPosts.first().isPinned)
assertNull(response.communityPosts.last().imageUrl)
assertNull(response.communityPosts.last().audioUrl)
assertEquals(1, response.page)
assertEquals(20, response.size)
assertTrue(response.hasNext)
val mapper = ObjectMapper().registerModule(KotlinModule.Builder().build())
val json = mapper.readTree(mapper.writeValueAsString(response))
assertTrue(json["hasNext"].asBoolean())
assertTrue(json["communityPosts"][0]["isCommentAvailable"].asBoolean())
assertTrue(json["communityPosts"][0]["isPinned"].asBoolean())
}
@Test
@DisplayName("커뮤니티 탭 facade는 query service 결과를 공개 응답 DTO로 변환한다")
fun shouldMapCommunityTabQueryResultToPublicResponse() {
val service = Mockito.mock(CreatorChannelCommunityQueryService::class.java)
val facade = CreatorChannelCommunityFacade(service)
val viewer = createMember(id = 10L)
val now = LocalDateTime.of(2026, 6, 21, 12, 0)
Mockito.doReturn(createTab()).`when`(service).getCommunityTab(
creatorId = 1L,
viewer = viewer,
page = -1,
size = 100,
now = now
)
val response = facade.getCommunityTab(
creatorId = 1L,
viewer = viewer,
page = -1,
size = 100,
now = now
)
assertEquals(2, response.communityPostCount)
assertEquals(101L, response.communityPosts.first().postId)
assertEquals("https://cdn.test/profile.png", response.communityPosts.first().creatorProfileUrl)
assertTrue(response.communityPosts.first().existOrdered)
assertFalse(response.communityPosts.last().isCommentAvailable)
assertEquals(1, response.page)
assertEquals(20, response.size)
assertTrue(response.hasNext)
}
private fun createMember(id: Long): Member {
return Member(
email = "viewer$id@test.com",
password = "password",
nickname = "viewer$id",
role = MemberRole.USER
).apply { this.id = id }
}
private fun createTab(): CreatorChannelCommunityTab {
return CreatorChannelCommunityTab(
communityPostCount = 2,
communityPosts = listOf(
CreatorChannelCommunityPost(
postId = 101L,
creatorId = 1L,
creatorNickname = "creator",
creatorProfileUrl = "https://cdn.test/profile.png",
imageUrl = "https://cdn.test/image.png",
audioUrl = "https://signed.test/audio",
content = "paid content",
price = 100,
createdAt = LocalDateTime.of(2026, 6, 21, 3, 30),
existOrdered = true,
isCommentAvailable = true,
likeCount = 7,
commentCount = 3,
isPinned = true
),
CreatorChannelCommunityPost(
postId = 102L,
creatorId = 1L,
creatorNickname = "creator",
creatorProfileUrl = "https://cdn.test/profile.png",
imageUrl = null,
audioUrl = null,
content = "masked...",
price = 50,
createdAt = LocalDateTime.of(2026, 6, 21, 3, 0),
existOrdered = false,
isCommentAvailable = false,
likeCount = 1,
commentCount = 0,
isPinned = false
)
),
page = CreatorChannelPage(page = 1, size = 20),
hasNext = true
)
}
}