feat(creatorname): 레거시 조회와 검색에 언어별 이름을 적용한다
This commit is contained in:
+2
-1
@@ -94,7 +94,8 @@ class LiveRecommendRepositoryTest @Autowired constructor(
|
||||
memberId = viewer.id!!,
|
||||
offset = 0,
|
||||
limit = 20,
|
||||
isBlocked = { false }
|
||||
isBlocked = { false },
|
||||
lang = Lang.KO
|
||||
)
|
||||
|
||||
assertEquals(2, result.size)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package kr.co.vividnext.sodalive.live.recommend
|
||||
|
||||
import kr.co.vividnext.sodalive.i18n.Lang
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.auth.Auth
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
@@ -28,7 +29,8 @@ class LiveRecommendServiceTest {
|
||||
repository = repository,
|
||||
blockMemberRepository = blockMemberRepository,
|
||||
memberContentPreferenceService = memberContentPreferenceService,
|
||||
liveRecommendCacheService = liveRecommendCacheService
|
||||
liveRecommendCacheService = liveRecommendCacheService,
|
||||
langContext = LangContext()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+523
@@ -0,0 +1,523 @@
|
||||
package kr.co.vividnext.sodalive.live.room
|
||||
|
||||
import kr.co.vividnext.sodalive.aws.s3.S3Uploader
|
||||
import kr.co.vividnext.sodalive.can.use.CanUsage
|
||||
import kr.co.vividnext.sodalive.can.use.UseCan
|
||||
import kr.co.vividnext.sodalive.can.use.UseCanRepository
|
||||
import kr.co.vividnext.sodalive.fcm.FcmService
|
||||
import kr.co.vividnext.sodalive.i18n.Lang
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.live.recommend.LiveRecommendService
|
||||
import kr.co.vividnext.sodalive.live.reservation.LiveReservation
|
||||
import kr.co.vividnext.sodalive.live.reservation.LiveReservationRepository
|
||||
import kr.co.vividnext.sodalive.live.reservation.LiveReservationService
|
||||
import kr.co.vividnext.sodalive.live.reservation.MakeLiveReservationRequest
|
||||
import kr.co.vividnext.sodalive.live.room.info.LiveRoomInfo
|
||||
import kr.co.vividnext.sodalive.live.room.info.LiveRoomInfoRedisRepository
|
||||
import kr.co.vividnext.sodalive.live.room.info.LiveRoomMemberRole
|
||||
import kr.co.vividnext.sodalive.live.room.visit.LiveRoomVisitService
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.member.MemberRole
|
||||
import kr.co.vividnext.sodalive.member.following.CreatorFollowing
|
||||
import kr.co.vividnext.sodalive.member.following.CreatorFollowingRepository
|
||||
import kr.co.vividnext.sodalive.support.EmbeddedRedisInitializer
|
||||
import org.hibernate.SessionFactory
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions.assertAll
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.mock.mockito.MockBean
|
||||
import org.springframework.cache.CacheManager
|
||||
import org.springframework.data.domain.PageRequest
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.mock.web.MockHttpServletRequest
|
||||
import org.springframework.test.annotation.DirtiesContext
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
import org.springframework.transaction.annotation.Propagation
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.context.request.RequestContextHolder
|
||||
import org.springframework.web.context.request.ServletRequestAttributes
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.EntityManagerFactory
|
||||
|
||||
@SpringBootTest(
|
||||
properties = [
|
||||
"spring.cache.type=none",
|
||||
"spring.jpa.properties.hibernate.generate_statistics=true",
|
||||
"jwt.secret=MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1Njc4OWFiY2RlZg==",
|
||||
"agora.app-id=0123456789abcdef0123456789abcdef",
|
||||
"agora.app-certificate=0123456789abcdef0123456789abcdef"
|
||||
]
|
||||
)
|
||||
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
|
||||
@Transactional
|
||||
class LiveRoomLocalizedNameIntegrationTest @Autowired constructor(
|
||||
private val service: LiveRoomService,
|
||||
private val reservationService: LiveReservationService,
|
||||
private val reservationRepository: LiveReservationRepository,
|
||||
private val visitService: LiveRoomVisitService,
|
||||
private val recommendService: LiveRecommendService,
|
||||
private val followingRepository: CreatorFollowingRepository,
|
||||
private val useCanRepository: UseCanRepository,
|
||||
private val roomRepository: LiveRoomRepository,
|
||||
private val roomInfoRepository: LiveRoomInfoRedisRepository,
|
||||
private val memberRepository: MemberRepository,
|
||||
private val jdbcTemplate: JdbcTemplate,
|
||||
private val cacheManager: CacheManager,
|
||||
private val entityManagerFactory: EntityManagerFactory,
|
||||
private val langContext: LangContext
|
||||
) {
|
||||
@MockBean
|
||||
private lateinit var fcmService: FcmService
|
||||
|
||||
@MockBean
|
||||
private lateinit var s3Uploader: S3Uploader
|
||||
|
||||
private val roomIds = mutableListOf<Long>()
|
||||
private val finishedLiveCacheKeys = mutableListOf<String>()
|
||||
|
||||
@BeforeEach
|
||||
fun setUpRequest() {
|
||||
RequestContextHolder.setRequestAttributes(ServletRequestAttributes(MockHttpServletRequest()))
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun resetRequestAndRemoveRoomInfo() {
|
||||
roomIds.forEach { roomInfoRepository.deleteById(it) }
|
||||
finishedLiveCacheKeys.forEach { cacheManager.getCache("cache_ttl_10_minutes")?.evict(it) }
|
||||
RequestContextHolder.resetRequestAttributes()
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("라이브 info는 모든 멤버 목록을 요청 언어로 복사하고 역할과 공유 Redis 원본을 보존한다")
|
||||
fun shouldRenderRoomInfoMemberNamesWithoutMutatingSharedRedisMembership() {
|
||||
val fixture = createFixture()
|
||||
langContext.setLang(Lang.JA)
|
||||
val japanese = service.getRoomInfo(fixture.roomId, fixture.viewer)
|
||||
langContext.setLang(Lang.KO)
|
||||
val korean = service.getRoomInfo(fixture.roomId, fixture.viewer)
|
||||
val stored = roomInfoRepository.findById(fixture.roomId).orElseThrow()
|
||||
|
||||
assertAll(
|
||||
{ assertEquals("日本-host", japanese.creatorNickname) },
|
||||
{ assertEquals("日本-host", japanese.speakerList.single().nickname) },
|
||||
{ assertEquals("日本-manager", japanese.managerList.single().nickname) },
|
||||
{ assertEquals(listOf("viewer", "fallback"), japanese.listenerList.map { it.nickname }) },
|
||||
{ assertEquals(LiveRoomMemberRole.SPEAKER, japanese.speakerList.single().role) },
|
||||
{ assertEquals(LiveRoomMemberRole.MANAGER, japanese.managerList.single().role) },
|
||||
{ assertEquals("host", korean.creatorNickname) },
|
||||
{ assertEquals("host", korean.speakerList.single().nickname) },
|
||||
{ assertEquals("manager", korean.managerList.single().nickname) },
|
||||
{ assertEquals("host", stored.speakerList.single().nickname) },
|
||||
{ assertEquals("manager", stored.managerList.single().nickname) },
|
||||
{ assertEquals("host", memberRepository.findById(fixture.host.id!!).orElseThrow().nickname) }
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("라이브 상세와 멤버 프로필의 현재 이름은 JA 별칭이며 USER와 비활성 별칭은 원본이다")
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
|
||||
fun shouldRenderCurrentRoomDetailAndMemberProfileNames() {
|
||||
val fixture = createFixture()
|
||||
langContext.setLang(Lang.JA)
|
||||
|
||||
val detail = service.getRoomDetail(fixture.roomId, fixture.viewer, "UTC")
|
||||
val hostProfile = service.getUserProfile(fixture.roomId, fixture.host.id!!, fixture.viewer)
|
||||
val viewerProfile = service.getUserProfile(fixture.roomId, fixture.viewer.id!!, fixture.viewer)
|
||||
|
||||
assertAll(
|
||||
{ assertEquals("日本-host", detail.manager!!.nickname) },
|
||||
{ assertEquals("日本-host", detail.participatingUsers.single { it.id == fixture.host.id }.nickname) },
|
||||
{ assertEquals("日本-manager", detail.participatingUsers.single { it.id == fixture.manager.id }.nickname) },
|
||||
{ assertEquals("viewer", detail.participatingUsers.single { it.id == fixture.viewer.id }.nickname) },
|
||||
{ assertEquals("fallback", detail.participatingUsers.single { it.id == fixture.fallback.id }.nickname) },
|
||||
{ assertEquals("日本-host", hostProfile.nickname) },
|
||||
{ assertEquals("viewer", viewerProfile.nickname) }
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("현재 후원 룰렛 메시지 이름은 요청별로 렌더링하며 비밀 필터와 본문 UUID 및 Redis 원본은 보존한다")
|
||||
fun shouldRenderDonationAndRouletteNamesOnCopiesAfterSecretFiltering() {
|
||||
val fixture = createFixture()
|
||||
val roomInfo = roomInfoRepository.findById(fixture.roomId).orElseThrow()
|
||||
roomInfo.addDonationMessage(fixture.manager.id!!, "manager", false, 10, "manager 후원 본문")
|
||||
roomInfo.addRouletteMessage(fixture.manager.id!!, "manager", "manager 룰렛 결과")
|
||||
roomInfo.addDonationMessage(fixture.viewer.id!!, "viewer", false, 10, "viewer 본문")
|
||||
roomInfo.addDonationMessage(fixture.manager.id!!, "manager", true, 10, "비밀 본문")
|
||||
roomInfoRepository.save(roomInfo)
|
||||
langContext.setLang(Lang.JA)
|
||||
val japanese = service.getDonationMessageList(fixture.roomId, fixture.viewer)
|
||||
langContext.setLang(Lang.KO)
|
||||
val korean = service.getDonationMessageList(fixture.roomId, fixture.viewer)
|
||||
val stored = roomInfoRepository.findById(fixture.roomId).orElseThrow().donationMessageList
|
||||
|
||||
assertAll(
|
||||
{ assertEquals(listOf("日本-manager", "日本-manager", "viewer"), japanese.map { it.nickname }) },
|
||||
{ assertEquals(listOf("manager", "manager", "viewer"), korean.map { it.nickname }) },
|
||||
{ assertEquals(listOf("manager 후원 본문", "manager 룰렛 결과", "viewer 본문"), japanese.map { it.donationMessage }) },
|
||||
{ assertEquals(korean.map { it.uuid }, japanese.map { it.uuid }) },
|
||||
{ assertEquals(listOf("manager", "manager", "viewer", "manager"), stored.map { it.nickname }) },
|
||||
{ assertEquals(4, stored.size) }
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("최근 종료 라이브의 현재 이름은 같은 회원의 KO 조회 캐시 이후에도 JA 요청을 따른다")
|
||||
fun shouldRenderJapaneseFinishedLiveNameAfterKoreanCacheRead() {
|
||||
val fixture = createFixture()
|
||||
val room = roomRepository.findById(fixture.roomId).orElseThrow()
|
||||
room.isActive = false
|
||||
fixture.host.profileImage = "profile/host.png"
|
||||
roomRepository.flush()
|
||||
val cacheKey = "getLatestFinishedLive:${fixture.viewer.id}"
|
||||
finishedLiveCacheKeys.add(cacheKey)
|
||||
val cache = requireNotNull(cacheManager.getCache("cache_ttl_10_minutes"))
|
||||
cache.evict(cacheKey)
|
||||
val statistics = entityManagerFactory.unwrap(SessionFactory::class.java).statistics
|
||||
statistics.clear()
|
||||
langContext.setLang(Lang.KO)
|
||||
val korean = service.getLatestFinishedLive(fixture.viewer).single { it.memberId == fixture.host.id }
|
||||
assertEquals(1L, currentNameQueryCount())
|
||||
val roomListQuery = statistics.queries.single { it.contains("from LiveRoom") }
|
||||
val roomListExecutions = statistics.getQueryStatistics(roomListQuery).executionCount
|
||||
val cached = cache.get(cacheKey)?.get()
|
||||
assertNotNull(cached)
|
||||
assertEquals(1L, roomListExecutions)
|
||||
assertEquals("host", (cached as List<*>).filterIsInstance<GetLatestFinishedLiveResponse>().single().nickname)
|
||||
langContext.setLang(Lang.JA)
|
||||
val nameQueryCountBeforeHit = currentNameQueryCount()
|
||||
val japanese = service.getLatestFinishedLive(fixture.viewer).single { it.memberId == fixture.host.id }
|
||||
assertEquals(1L, currentNameQueryCount() - nameQueryCountBeforeHit)
|
||||
assertEquals(roomListExecutions, statistics.getQueryStatistics(roomListQuery).executionCount)
|
||||
assertEquals(cached, cache.get(cacheKey)?.get())
|
||||
fixture.host.nickname = "updated-host"
|
||||
memberRepository.flush()
|
||||
jdbcTemplate.update("UPDATE creator_localized_name SET is_active = false WHERE member_id = ?", fixture.host.id!!)
|
||||
val nameQueryCountBeforeFallback = currentNameQueryCount()
|
||||
val fallback = service.getLatestFinishedLive(fixture.viewer).single { it.memberId == fixture.host.id }
|
||||
assertEquals(1L, currentNameQueryCount() - nameQueryCountBeforeFallback)
|
||||
|
||||
assertEquals("host", korean.nickname)
|
||||
assertEquals("日本-host", japanese.nickname)
|
||||
assertEquals("updated-host", fallback.nickname)
|
||||
assertEquals("host", korean.nickname)
|
||||
assertEquals(roomListExecutions, statistics.getQueryStatistics(roomListQuery).executionCount)
|
||||
assertEquals(cached, cache.get(cacheKey)?.get())
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO creator_localized_name (member_id, lang, display_name, is_active, created_at, updated_at) " +
|
||||
"VALUES (?, 'EN', 'English host', true, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)",
|
||||
fixture.host.id!!
|
||||
)
|
||||
langContext.setLang(Lang.EN)
|
||||
val nameQueryCountBeforeEnglishHit = currentNameQueryCount()
|
||||
val english = service.getLatestFinishedLive(fixture.viewer).single { it.memberId == fixture.host.id }
|
||||
assertEquals("English host", english.nickname)
|
||||
assertEquals(1L, currentNameQueryCount() - nameQueryCountBeforeEnglishHit)
|
||||
assertEquals(roomListExecutions, statistics.getQueryStatistics(roomListQuery).executionCount)
|
||||
assertEquals(cached, cache.get(cacheKey)?.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("언어 중립 live feed와 종료 캐시는 별칭 해제 후 변경된 현재 원본으로 fallback한다")
|
||||
fun shouldFallBackToCurrentOriginalWithoutRewritingNeutralRedisNames() {
|
||||
val fixture = createFixture()
|
||||
val info = roomInfoRepository.findById(fixture.roomId).orElseThrow()
|
||||
info.addDonationMessage(fixture.host.id!!, "host", false, 10, "host 본문")
|
||||
roomInfoRepository.save(info)
|
||||
fixture.host.nickname = "updated-host"
|
||||
memberRepository.flush()
|
||||
jdbcTemplate.update("UPDATE creator_localized_name SET is_active = false WHERE member_id = ?", fixture.host.id!!)
|
||||
langContext.setLang(Lang.JA)
|
||||
|
||||
val response = service.getRoomInfo(fixture.roomId, fixture.viewer)
|
||||
val messages = service.getDonationMessageList(fixture.roomId, fixture.viewer)
|
||||
val stored = roomInfoRepository.findById(fixture.roomId).orElseThrow()
|
||||
|
||||
assertEquals("updated-host", response.creatorNickname)
|
||||
assertEquals("updated-host", response.speakerList.single().nickname)
|
||||
assertEquals("updated-host", messages.single().nickname)
|
||||
assertEquals("host", stored.speakerList.single().nickname)
|
||||
assertEquals("host", stored.donationMessageList.single().nickname)
|
||||
assertEquals("host 본문", messages.single().donationMessage)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("예약 생성·목록·상세와 최근 방문자 조회는 실제 크리에이터 소유 ID로 JA 이름을 표시한다")
|
||||
fun shouldLocalizeReservationAndRecentVisitorNames() {
|
||||
val fixture = createFixture()
|
||||
langContext.setLang(Lang.JA)
|
||||
val reservation = reservationService.makeReservation(
|
||||
MakeLiveReservationRequest(fixture.roomId, "web", "UTC"),
|
||||
fixture.viewer.id!!
|
||||
)
|
||||
val statistics = entityManagerFactory.unwrap(SessionFactory::class.java).statistics
|
||||
statistics.clear()
|
||||
val listed = reservationService.getReservationList(fixture.viewer.id!!, true, "UTC").single()
|
||||
val detail = reservationService.getReservation(reservation.reservationId, fixture.viewer.id!!, "UTC")
|
||||
assertEquals(2L, statistics.queryExecutionCount, statistics.queries.joinToString("\n"))
|
||||
val room = roomRepository.findById(fixture.roomId).orElseThrow()
|
||||
visitService.roomVisit(room, fixture.viewer)
|
||||
visitService.roomVisit(room, fixture.manager)
|
||||
statistics.clear()
|
||||
val visitor = visitService.getRecentVisitRoomUsers(fixture.viewer).single()
|
||||
assertEquals(2L, statistics.queryExecutionCount, statistics.queries.joinToString("\n"))
|
||||
|
||||
assertEquals("日本-host", reservation.nickname)
|
||||
assertEquals("日本-host", listed.masterNickname)
|
||||
assertEquals("日本-host", detail.masterNickname)
|
||||
assertEquals(fixture.manager.id, visitor.id)
|
||||
assertEquals("日本-manager", visitor.nickname)
|
||||
langContext.setLang(Lang.KO)
|
||||
assertEquals("manager", visitService.getRecentVisitRoomUsers(fixture.viewer).single().nickname)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("추천과 팔로잉의 on-air 및 off-air 분기는 요청별 이름을 표시하고 count와 순서를 보존한다")
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
|
||||
fun shouldLocalizeRecommendedAndFollowingChannels() {
|
||||
val fixture = createFixture()
|
||||
followingRepository.saveAndFlush(
|
||||
CreatorFollowing().apply {
|
||||
member = fixture.viewer
|
||||
creator = fixture.host
|
||||
}
|
||||
)
|
||||
followingRepository.saveAndFlush(
|
||||
CreatorFollowing().apply {
|
||||
member = fixture.viewer
|
||||
creator = fixture.manager
|
||||
}
|
||||
)
|
||||
langContext.setLang(Lang.JA)
|
||||
|
||||
val statistics = entityManagerFactory.unwrap(SessionFactory::class.java).statistics
|
||||
statistics.clear()
|
||||
val recommended = recommendService.getRecommendChannelList(null).associateBy { it.creatorId }
|
||||
val aliasQueries = statistics.queries.filter {
|
||||
Regex("""(?is)^select\s+\w+\.memberId,\s*\w+\.displayName\s+from\s+CreatorLocalizedNameEntity\b""")
|
||||
.containsMatchIn(it)
|
||||
}
|
||||
val aliasQueryCount = aliasQueries.sumOf { statistics.getQueryStatistics(it).executionCount }
|
||||
val queryCount = statistics.queryExecutionCount
|
||||
val following = recommendService.getFollowingChannelList(fixture.viewer).associateBy { it.creatorId }
|
||||
val all = recommendService.getFollowingAllChannelList(fixture.viewer, PageRequest.of(0, 20))
|
||||
|
||||
assertEquals("日本-host", recommended.getValue(fixture.host.id!!).nickname)
|
||||
assertEquals("日本-manager", recommended.getValue(fixture.manager.id!!).nickname)
|
||||
assertEquals("fallback", recommended.getValue(fixture.fallback.id!!).nickname)
|
||||
assertEquals("日本-host", following.getValue(fixture.host.id!!).nickname)
|
||||
assertEquals("日本-manager", following.getValue(fixture.manager.id!!).nickname)
|
||||
assertEquals(2, all.totalCount)
|
||||
assertEquals(setOf("日本-host", "日本-manager"), all.items.map { it.nickname }.toSet())
|
||||
langContext.setLang(Lang.KO)
|
||||
assertEquals(
|
||||
setOf("host", "manager"),
|
||||
recommendService.getFollowingAllChannelList(fixture.viewer, PageRequest.of(0, 20)).items.map { it.nickname }.toSet()
|
||||
)
|
||||
assertEquals(0L, aliasQueryCount, "Standalone alias SELECTs (total queries=$queryCount): $aliasQueries")
|
||||
assertNoStandaloneNameQueries()
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO creator_localized_name (member_id, lang, display_name, is_active, created_at, updated_at) " +
|
||||
"VALUES (?, 'EN', 'English host', true, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)",
|
||||
fixture.host.id!!
|
||||
)
|
||||
langContext.setLang(Lang.EN)
|
||||
assertEquals(
|
||||
setOf("English host", "manager"),
|
||||
recommendService.getFollowingAllChannelList(fixture.viewer, PageRequest.of(0, 20)).items.map { it.nickname }.toSet()
|
||||
)
|
||||
assertNoStandaloneNameQueries()
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("후원과 하트 집계는 donor ID로 이름만 바꾸고 USER·금액·비밀 합계와 공개 DTO 필드를 보존한다")
|
||||
fun shouldLocalizeDonationAndHeartDonorNamesWithoutChangingAmounts() {
|
||||
val fixture = createFixture()
|
||||
val room = roomRepository.findById(fixture.roomId).orElseThrow()
|
||||
listOf(CanUsage.DONATION, CanUsage.HEART).forEach { usage ->
|
||||
useCanRepository.saveAndFlush(
|
||||
UseCan(usage, 10, 2).apply {
|
||||
member = fixture.manager
|
||||
this.room = room
|
||||
}
|
||||
)
|
||||
useCanRepository.saveAndFlush(
|
||||
UseCan(usage, 5, 1).apply {
|
||||
member = fixture.viewer
|
||||
this.room = room
|
||||
}
|
||||
)
|
||||
}
|
||||
langContext.setLang(Lang.JA)
|
||||
|
||||
val statistics = entityManagerFactory.unwrap(SessionFactory::class.java).statistics
|
||||
statistics.clear()
|
||||
val donations = service.getDonationStatus(fixture.roomId, fixture.host.id!!)
|
||||
val hearts = service.getHeartList(fixture.roomId)
|
||||
assertEquals(3L, statistics.queryExecutionCount, statistics.queries.joinToString("\n"))
|
||||
|
||||
assertEquals(listOf("日本-manager", "viewer"), donations.donationList.map { it.nickname })
|
||||
assertEquals(listOf("日本-manager", "viewer"), hearts.heartList.map { it.nickname })
|
||||
assertEquals(18, donations.totalCan)
|
||||
assertEquals(0, donations.totalSecretCan)
|
||||
assertEquals(18, hearts.totalHeart)
|
||||
assertEquals(2, hearts.totalCount)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("진행·날짜별 예약·예정 라이브 목록은 EN 이름을 조인하고 USER·미등록·비활성 소유자를 유지한다")
|
||||
fun shouldJoinEnglishNamesInEveryDatabaseRoomListWithoutMutatingOwners() {
|
||||
val fixture = createFixture()
|
||||
val owners = listOf(fixture.host, fixture.manager, fixture.viewer, fixture.fallback)
|
||||
listOf(fixture.host, fixture.viewer, fixture.fallback).forEach {
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO creator_localized_name (member_id, lang, display_name, is_active, created_at, updated_at) " +
|
||||
"VALUES (?, 'EN', ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)",
|
||||
it.id!!,
|
||||
"EN-${it.nickname}",
|
||||
it != fixture.fallback
|
||||
)
|
||||
}
|
||||
val rooms = listOf(roomRepository.findById(fixture.roomId).orElseThrow()) + owners.drop(1).map { owner ->
|
||||
roomRepository.saveAndFlush(
|
||||
LiveRoom("${owner.nickname} room", "notice", LocalDateTime.now(), 10, "cover.png", isAdult = false).apply {
|
||||
member = owner
|
||||
channelName = "live_${owner.id}"
|
||||
}
|
||||
)
|
||||
}
|
||||
val expected = mapOf(
|
||||
fixture.host.id to "EN-host",
|
||||
fixture.manager.id to "manager",
|
||||
fixture.viewer.id to "viewer",
|
||||
fixture.fallback.id to "fallback"
|
||||
)
|
||||
val statistics = entityManagerFactory.unwrap(SessionFactory::class.java).statistics
|
||||
statistics.clear()
|
||||
|
||||
val current = roomRepository.getLiveRoomListNow(0, 20, "UTC", null, false, true, null, Lang.EN)
|
||||
assertEquals(expected, current.associate { it.room.member!!.id to it.creatorNickname })
|
||||
assertEquals(1L, statistics.queryExecutionCount)
|
||||
|
||||
owners.forEach { owner ->
|
||||
reservationRepository.saveAndFlush(
|
||||
LiveReservation().apply {
|
||||
member = owner
|
||||
room = rooms.first()
|
||||
}
|
||||
)
|
||||
}
|
||||
statistics.clear()
|
||||
val bookers = reservationRepository.getReservationList(fixture.roomId, Lang.EN)
|
||||
assertEquals(expected, bookers.associate { it.id to it.nickname })
|
||||
assertEquals(1L, statistics.queryExecutionCount)
|
||||
statistics.clear()
|
||||
val reservation = reservationRepository.getReservationListByMemberId(fixture.viewer.id!!, true, Lang.EN).single()
|
||||
val reserved = reservationRepository.getReservationByReservationAndMemberId(reservation.id, fixture.viewer.id!!, Lang.EN)
|
||||
assertEquals("EN-host", reservation.masterNickname)
|
||||
assertEquals("EN-host", reserved!!.masterNickname)
|
||||
assertEquals(2L, statistics.queryExecutionCount)
|
||||
|
||||
val date = LocalDateTime.now().plusDays(1).withHour(12).withMinute(0)
|
||||
rooms.forEach {
|
||||
it.channelName = null
|
||||
it.beginDateTime = date
|
||||
}
|
||||
roomRepository.flush()
|
||||
statistics.clear()
|
||||
val dated = roomRepository.getLiveRoomListReservationWithDate(
|
||||
date.toLocalDate().atStartOfDay(),
|
||||
0,
|
||||
20,
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
null,
|
||||
Lang.EN
|
||||
)
|
||||
val upcoming = roomRepository.getLiveRoomListReservationWithoutDate("UTC", null, false, true, null, Lang.EN)
|
||||
|
||||
assertEquals(expected, dated.associate { it.room.member!!.id to it.creatorNickname })
|
||||
assertEquals(expected, upcoming.associate { it.room.member!!.id to it.creatorNickname })
|
||||
assertEquals(2L, statistics.queryExecutionCount)
|
||||
assertEquals(listOf("host", "manager", "viewer", "fallback"), owners.map { it.nickname })
|
||||
assertNoStandaloneNameQueries()
|
||||
}
|
||||
|
||||
private fun assertNoStandaloneNameQueries() {
|
||||
val statistics = entityManagerFactory.unwrap(SessionFactory::class.java).statistics
|
||||
val nameQueries = statistics.queries.filter {
|
||||
Regex("""(?is)\bfrom\s+CreatorLocalizedNameEntity\b""").containsMatchIn(it) ||
|
||||
Regex("""(?is)^select\s+\w+\.id,\s*coalesce\([^)]*\)\s+from\s+Member\b""").containsMatchIn(it)
|
||||
}
|
||||
assertEquals(0L, nameQueries.sumOf { statistics.getQueryStatistics(it).executionCount }, nameQueries.joinToString("\n"))
|
||||
}
|
||||
|
||||
private fun currentNameQueryCount(): Long {
|
||||
val statistics = entityManagerFactory.unwrap(SessionFactory::class.java).statistics
|
||||
return statistics.queries.filter { it.contains("from Member") && it.contains("CreatorLocalizedNameEntity") }
|
||||
.sumOf { statistics.getQueryStatistics(it).executionCount }
|
||||
}
|
||||
|
||||
private fun createFixture(): Fixture {
|
||||
val host = savedMember("host", MemberRole.CREATOR)
|
||||
val manager = savedMember("manager", MemberRole.CREATOR)
|
||||
val viewer = savedMember("viewer", MemberRole.USER)
|
||||
val fallback = savedMember("fallback", MemberRole.CREATOR, activeAlias = false)
|
||||
val room = roomRepository.saveAndFlush(
|
||||
LiveRoom(
|
||||
title = "room title",
|
||||
notice = "notice",
|
||||
beginDateTime = LocalDateTime.now().minusMinutes(1),
|
||||
numberOfPeople = 10,
|
||||
coverImage = "cover.png",
|
||||
isAdult = false
|
||||
).apply {
|
||||
member = host
|
||||
channelName = "localized_live_${host.id}"
|
||||
}
|
||||
)
|
||||
roomIds.add(room.id!!)
|
||||
roomInfoRepository.save(
|
||||
LiveRoomInfo(room.id!!).apply {
|
||||
addSpeaker(host, "https://cdn.test")
|
||||
addManager(manager, "https://cdn.test")
|
||||
addListener(viewer, "https://cdn.test")
|
||||
addListener(fallback, "https://cdn.test")
|
||||
}
|
||||
)
|
||||
return Fixture(room.id!!, host, manager, viewer, fallback)
|
||||
}
|
||||
|
||||
private fun savedMember(nickname: String, role: MemberRole, activeAlias: Boolean = true): Member {
|
||||
val member = memberRepository.saveAndFlush(
|
||||
Member(
|
||||
email = "$nickname@localized-live.test",
|
||||
password = "pw",
|
||||
nickname = nickname,
|
||||
profileImage = "profile/$nickname.png",
|
||||
role = role,
|
||||
isVisibleDonationRank = false
|
||||
)
|
||||
)
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO creator_localized_name (member_id, lang, display_name, is_active, created_at, updated_at) " +
|
||||
"VALUES (?, 'JA', ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)",
|
||||
member.id!!,
|
||||
"日本-$nickname",
|
||||
activeAlias
|
||||
)
|
||||
return member
|
||||
}
|
||||
|
||||
private data class Fixture(val roomId: Long, val host: Member, val manager: Member, val viewer: Member, val fallback: Member)
|
||||
}
|
||||
+15
-6
@@ -12,6 +12,7 @@ import kr.co.vividnext.sodalive.content.ContentType
|
||||
import kr.co.vividnext.sodalive.explorer.ExplorerQueryRepository
|
||||
import kr.co.vividnext.sodalive.explorer.profile.CreatorDonationRankingService
|
||||
import kr.co.vividnext.sodalive.fcm.PushTokenRepository
|
||||
import kr.co.vividnext.sodalive.i18n.Lang
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.live.reservation.LiveReservationRepository
|
||||
@@ -30,6 +31,7 @@ import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.MemberContentPreferenceService
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.ViewerContentPreference
|
||||
import kr.co.vividnext.sodalive.v2.creatorname.application.CreatorLocalizedNameService
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
@@ -106,6 +108,7 @@ class LiveRoomServiceAdultVisibilityPolicyTest {
|
||||
menuService = menuService,
|
||||
messageSource = messageSource,
|
||||
langContext = langContext,
|
||||
localizedNameService = mock<CreatorLocalizedNameService>(),
|
||||
repository = repository,
|
||||
rouletteRepository = rouletteRepository,
|
||||
roomInfoRepository = roomInfoRepository,
|
||||
@@ -152,7 +155,8 @@ class LiveRoomServiceAdultVisibilityPolicyTest {
|
||||
memberId = 100L,
|
||||
isCreator = false,
|
||||
isAdult = true,
|
||||
effectiveGender = Gender.NONE
|
||||
effectiveGender = Gender.NONE,
|
||||
lang = Lang.KO
|
||||
)
|
||||
).thenReturn(emptyList())
|
||||
|
||||
@@ -172,7 +176,8 @@ class LiveRoomServiceAdultVisibilityPolicyTest {
|
||||
memberId = 100L,
|
||||
isCreator = false,
|
||||
isAdult = true,
|
||||
effectiveGender = Gender.NONE
|
||||
effectiveGender = Gender.NONE,
|
||||
lang = Lang.KO
|
||||
)
|
||||
}
|
||||
|
||||
@@ -187,7 +192,8 @@ class LiveRoomServiceAdultVisibilityPolicyTest {
|
||||
memberId = null,
|
||||
isCreator = false,
|
||||
isAdult = true,
|
||||
effectiveGender = null
|
||||
effectiveGender = null,
|
||||
lang = Lang.KO
|
||||
)
|
||||
).thenReturn(emptyList())
|
||||
|
||||
@@ -207,7 +213,8 @@ class LiveRoomServiceAdultVisibilityPolicyTest {
|
||||
memberId = null,
|
||||
isCreator = false,
|
||||
isAdult = true,
|
||||
effectiveGender = null
|
||||
effectiveGender = null,
|
||||
lang = Lang.KO
|
||||
)
|
||||
}
|
||||
|
||||
@@ -222,7 +229,8 @@ class LiveRoomServiceAdultVisibilityPolicyTest {
|
||||
memberId = 200L,
|
||||
isCreator = false,
|
||||
isAdult = false,
|
||||
effectiveGender = Gender.NONE
|
||||
effectiveGender = Gender.NONE,
|
||||
lang = Lang.KO
|
||||
)
|
||||
).thenReturn(emptyList())
|
||||
|
||||
@@ -240,7 +248,8 @@ class LiveRoomServiceAdultVisibilityPolicyTest {
|
||||
memberId = 200L,
|
||||
isCreator = false,
|
||||
isAdult = false,
|
||||
effectiveGender = Gender.NONE
|
||||
effectiveGender = Gender.NONE,
|
||||
lang = Lang.KO
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import kr.co.vividnext.sodalive.member.MemberRole
|
||||
import kr.co.vividnext.sodalive.member.auth.Auth
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.MemberContentPreferenceService
|
||||
import kr.co.vividnext.sodalive.v2.creatorname.application.CreatorLocalizedNameService
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
@@ -70,6 +71,7 @@ class LiveRoomServiceTest {
|
||||
menuService = mock<LiveRoomMenuService>(),
|
||||
messageSource = mock<SodaMessageSource>(),
|
||||
langContext = LangContext(),
|
||||
localizedNameService = mock<CreatorLocalizedNameService>(),
|
||||
repository = repository,
|
||||
rouletteRepository = rouletteRepository,
|
||||
roomInfoRepository = roomInfoRepository,
|
||||
|
||||
Reference in New Issue
Block a user