feat(recommend): 조회 이력 성공 로그를 커밋 후 기록한다
This commit is contained in:
@@ -6,15 +6,20 @@ import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.springframework.boot.test.system.CapturedOutput
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@ExtendWith(OutputCaptureExtension::class)
|
||||
class CreatorContentViewHistoryServiceTest {
|
||||
private val port = FakeCreatorContentViewHistoryPort()
|
||||
private val service = CreatorContentViewHistoryService(port)
|
||||
|
||||
@Test
|
||||
@DisplayName("인증 회원의 콘텐츠 상세 진입 시 memberId/contentId/genreId/viewedAt을 저장한다")
|
||||
fun shouldRecordAuthenticatedMemberContentViewWithGenreAndViewedAt() {
|
||||
fun shouldRecordAuthenticatedMemberContentViewWithGenreAndViewedAt(output: CapturedOutput) {
|
||||
val viewedAt = LocalDateTime.of(2026, 5, 31, 10, 0)
|
||||
port.genreIdByContentId[20L] = 30L
|
||||
|
||||
@@ -31,22 +36,44 @@ class CreatorContentViewHistoryServiceTest {
|
||||
),
|
||||
port.savedRecords
|
||||
)
|
||||
assertTrue(output.out.contains("event=creator_content_view_history_record_success"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("조회 이력 저장 성공 로그는 트랜잭션 커밋 후 기록한다")
|
||||
fun shouldLogRecordSuccessAfterTransactionCommit(output: CapturedOutput) {
|
||||
port.genreIdByContentId[20L] = 30L
|
||||
TransactionSynchronizationManager.initSynchronization()
|
||||
try {
|
||||
service.recordView(memberId = 10L, contentId = 20L)
|
||||
|
||||
assertEquals(false, output.out.contains("event=creator_content_view_history_record_success"))
|
||||
TransactionSynchronizationManager.getSynchronizations().forEach { it.afterCommit() }
|
||||
} finally {
|
||||
TransactionSynchronizationManager.clearSynchronization()
|
||||
}
|
||||
|
||||
assertTrue(output.out.contains("event=creator_content_view_history_record_success"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("비회원 콘텐츠 상세 진입은 조회 이력을 저장하지 않는다")
|
||||
fun shouldNotRecordAnonymousContentView() {
|
||||
fun shouldNotRecordAnonymousContentView(output: CapturedOutput) {
|
||||
service.recordView(memberId = null, contentId = 20L)
|
||||
|
||||
assertTrue(port.savedRecords.isEmpty())
|
||||
assertTrue(output.out.contains("event=creator_content_view_history_record_skipped"))
|
||||
assertTrue(output.out.contains("reason=anonymous"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("콘텐츠의 활성 장르를 찾지 못하면 조회 이력을 저장하지 않는다")
|
||||
fun shouldNotRecordWhenContentGenreDoesNotExist() {
|
||||
fun shouldNotRecordWhenContentGenreDoesNotExist(output: CapturedOutput) {
|
||||
service.recordView(memberId = 10L, contentId = 20L)
|
||||
|
||||
assertTrue(port.savedRecords.isEmpty())
|
||||
assertTrue(output.out.contains("event=creator_content_view_history_record_skipped"))
|
||||
assertTrue(output.out.contains("reason=genre_not_found"))
|
||||
}
|
||||
|
||||
private class FakeCreatorContentViewHistoryPort : CreatorContentViewHistoryPort {
|
||||
|
||||
Reference in New Issue
Block a user