diff --git a/src/test/kotlin/kr/co/vividnext/sodalive/v2/api/home/following/adapter/in/web/HomeFollowingEndToEndTest.kt b/src/test/kotlin/kr/co/vividnext/sodalive/v2/api/home/following/adapter/in/web/HomeFollowingEndToEndTest.kt index ec618a9b..4324eb60 100644 --- a/src/test/kotlin/kr/co/vividnext/sodalive/v2/api/home/following/adapter/in/web/HomeFollowingEndToEndTest.kt +++ b/src/test/kotlin/kr/co/vividnext/sodalive/v2/api/home/following/adapter/in/web/HomeFollowingEndToEndTest.kt @@ -3,6 +3,9 @@ package kr.co.vividnext.sodalive.v2.api.home.following.adapter.`in`.web import kr.co.vividnext.sodalive.common.CountryContext import kr.co.vividnext.sodalive.content.AudioContent import kr.co.vividnext.sodalive.content.theme.AudioContentTheme +import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.CreatorCommunity +import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment.CreatorCommunityComment +import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.CreatorCommunityLike import kr.co.vividnext.sodalive.live.room.LiveRoom import kr.co.vividnext.sodalive.member.Member import kr.co.vividnext.sodalive.member.MemberAdapter @@ -87,10 +90,34 @@ class HomeFollowingEndToEndTest @Autowired constructor( .andExpect(jsonPath("$.data.monthlySchedules[0].scheduleId").value("LIVE:${fixture.liveId}")) .andExpect(jsonPath("$.data.monthlySchedules[1].scheduleId").value("AUDIO:${fixture.audioId}")) .andExpect(jsonPath("$.data.recentNews[0].newsId").value(fixture.rankedNewsId.toString())) + .andExpect(jsonPath("$.data.recentNews[0].type").value("CREATOR_RANKING")) + .andExpect(jsonPath("$.data.recentNews[0].visibleFromAtUtc").exists()) .andExpect(jsonPath("$.data.recentNews[0].creatorId").doesNotExist()) - .andExpect(jsonPath("$.data.recentNews[0].ranking").doesNotExist()) - .andExpect(jsonPath("$.data.recentNews[0].rank").value(7)) - .andExpect(jsonPath("$.data.recentNews[1].rank").value(nullValue())) + .andExpect(jsonPath("$.data.recentNews[0].rank").doesNotExist()) + .andExpect(jsonPath("$.data.recentNews[0].creatorRanking.rank").value(7)) + .andExpect(jsonPath("$.data.recentNews[0].creatorRanking.creatorId").value(fixture.creatorId)) + .andExpect(jsonPath("$.data.recentNews[0].audioContent").value(nullValue())) + .andExpect(jsonPath("$.data.recentNews[0].communityPost").value(nullValue())) + .andExpect(jsonPath("$.data.recentNews[1].type").value("COMMUNITY_POST")) + .andExpect(jsonPath("$.data.recentNews[1].communityPost.postId").value(fixture.freePostId)) + .andExpect(jsonPath("$.data.recentNews[1].communityPost.creatorProfileImage").value("https://cdn.test/creator.png")) + .andExpect(jsonPath("$.data.recentNews[1].communityPost.creatorNickname").value("home-following-creator")) + .andExpect(jsonPath("$.data.recentNews[1].communityPost.imageUrl").value("https://cdn.test/community/free.png")) + .andExpect(jsonPath("$.data.recentNews[1].communityPost.content").value("free community body")) + .andExpect(jsonPath("$.data.recentNews[1].communityPost.createdAt").exists()) + .andExpect(jsonPath("$.data.recentNews[1].communityPost.likeCount").value(1)) + .andExpect(jsonPath("$.data.recentNews[1].communityPost.commentCount").value(1)) + .andExpect(jsonPath("$.data.recentNews[1].creatorRanking").value(nullValue())) + .andExpect(jsonPath("$.data.recentNews[2].type").value("AUDIO_CONTENT")) + .andExpect(jsonPath("$.data.recentNews[2].audioContent.contentId").value(fixture.audioId)) + .andExpect(jsonPath("$.data.recentNews[2].audioContent.title").value("home-following-audio")) + .andExpect( + jsonPath("$.data.recentNews[2].audioContent.contentImageUrl") + .value("https://cdn.test/audio/home-following.png") + ) + .andExpect(jsonPath("$.data.recentNews[2].audioContent.releaseDate").doesNotExist()) + .andExpect(jsonPath("$.data.recentNews[2].communityPost").value(nullValue())) + .andExpect(jsonPath("$.data.recentNews[?(@.communityPost.postId == ${fixture.paidPostId})]").isEmpty) } private fun createFixture(): Fixture { @@ -110,7 +137,36 @@ class HomeFollowingEndToEndTest @Autowired constructor( val live = saveLiveRoom(creator, scheduleBaseUtc.plusHours(1), channelName = "on-air") val theme = saveTheme() val audio = saveAudioContent(creator, theme, scheduleBaseUtc.plusHours(2)) - val oldNews = saveNews(viewer.id!!, creator.id!!, "old-news", now.minusHours(2), rank = null) + audio.coverImage = "audio/home-following.png" + val freePost = saveCommunityPost(creator, "free community body", price = 0, imagePath = "community/free.png") + val paidPost = saveCommunityPost(creator, "paid community body", price = 10, imagePath = "community/paid.png") + saveCommunityLike(viewer, freePost, isActive = true) + saveCommunityComment(viewer, freePost, isActive = true) + saveNews(viewer.id!!, creator.id!!, "old-news", now.minusHours(2), rank = null) + val audioNews = saveNews( + memberId = viewer.id!!, + creatorId = creator.id!!, + sourceKey = "audio-news", + visibleFromAtUtc = now.minusHours(3), + newsType = FollowingNewsType.AUDIO_CONTENT, + targetId = audio.id!! + ) + val communityNews = saveNews( + memberId = viewer.id!!, + creatorId = creator.id!!, + sourceKey = "free-community-news", + visibleFromAtUtc = now.minusHours(2), + newsType = FollowingNewsType.COMMUNITY_POST, + targetId = freePost.id!! + ) + saveNews( + memberId = viewer.id!!, + creatorId = creator.id!!, + sourceKey = "paid-community-news", + visibleFromAtUtc = now.minusMinutes(30), + newsType = FollowingNewsType.COMMUNITY_POST, + targetId = paidPost.id!! + ) val rankedNews = saveNews(viewer.id!!, creator.id!!, "ranked-news", now.minusHours(1), rank = 7) val chatRoom = saveDmChatRoom(viewer, creator, now.minusMinutes(10)) entityManager.flush() @@ -123,7 +179,10 @@ class HomeFollowingEndToEndTest @Autowired constructor( audioId = audio.id!!, chatRoomId = chatRoom.id!!, rankedNewsId = rankedNews.id!!, - oldNewsId = oldNews.id!! + audioNewsId = audioNews.id!!, + communityNewsId = communityNews.id!!, + freePostId = freePost.id!!, + paidPostId = paidPost.id!! ) }!! } @@ -192,14 +251,16 @@ class HomeFollowingEndToEndTest @Autowired constructor( creatorId: Long, sourceKey: String, visibleFromAtUtc: LocalDateTime, - rank: Int? + rank: Int? = null, + newsType: FollowingNewsType = FollowingNewsType.CREATOR_RANKING, + targetId: Long = creatorId ): HomeFollowingNewsInbox { val news = HomeFollowingNewsInbox( memberId = memberId, creatorId = creatorId, - newsType = FollowingNewsType.CREATOR_RANKING, + newsType = newsType, sourceKey = sourceKey, - targetId = creatorId, + targetId = targetId, occurredAtUtc = visibleFromAtUtc.minusMinutes(30), visibleFromAtUtc = visibleFromAtUtc, creatorNickname = "home-following-creator", @@ -214,6 +275,39 @@ class HomeFollowingEndToEndTest @Autowired constructor( return news } + private fun saveCommunityPost(creator: Member, content: String, price: Int, imagePath: String): CreatorCommunity { + val post = CreatorCommunity( + content = content, + price = price, + isCommentAvailable = true, + isAdult = false, + imagePath = imagePath, + isActive = true + ).apply { + member = creator + } + entityManager.persist(post) + return post + } + + private fun saveCommunityLike(member: Member, post: CreatorCommunity, isActive: Boolean): CreatorCommunityLike { + val like = CreatorCommunityLike(isActive = isActive).apply { + this.member = member + creatorCommunity = post + } + entityManager.persist(like) + return like + } + + private fun saveCommunityComment(member: Member, post: CreatorCommunity, isActive: Boolean): CreatorCommunityComment { + val comment = CreatorCommunityComment(comment = "comment", isActive = isActive).apply { + this.member = member + creatorCommunity = post + } + entityManager.persist(comment) + return comment + } + private fun saveDmChatRoom(viewer: Member, creator: Member, messageCreatedAt: LocalDateTime): UserCreatorChatRoom { val room = UserCreatorChatRoom() entityManager.persist(room) @@ -241,6 +335,9 @@ class HomeFollowingEndToEndTest @Autowired constructor( val audioId: Long, val chatRoomId: Long, val rankedNewsId: Long, - val oldNewsId: Long + val audioNewsId: Long, + val communityNewsId: Long, + val freePostId: Long, + val paidPostId: Long ) }