feat(home): 응원 스냅샷 marker 저장을 지원한다
This commit is contained in:
+105
-2
@@ -77,6 +77,61 @@ class RecommendationSnapshotPersistenceAdapterTest @Autowired constructor(
|
||||
assertEquals(listOf(2L, 3L), snapshots.map { it.targetId })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldFindSnapshotsByExactSnapshotAtAndExcludeEmptyMarker() {
|
||||
val oldSnapshotAt = LocalDateTime.of(2026, 5, 28, 23, 59, 59)
|
||||
val snapshotAt = LocalDateTime.of(2026, 5, 29, 23, 59, 59)
|
||||
repository.saveAll(
|
||||
listOf(
|
||||
snapshot(RecommendedSectionType.CHEER_CREATOR, targetId = 1L, score = 999.0, snapshotAt = oldSnapshotAt),
|
||||
snapshot(RecommendedSectionType.CHEER_CREATOR, targetId = 0L, score = 0.0, snapshotAt = snapshotAt),
|
||||
snapshot(
|
||||
RecommendedSectionType.CHEER_CREATOR,
|
||||
targetId = 2L,
|
||||
score = 100.0,
|
||||
snapshotAt = snapshotAt,
|
||||
randomTieBreaker = 0.9
|
||||
),
|
||||
snapshot(
|
||||
RecommendedSectionType.CHEER_CREATOR,
|
||||
targetId = 3L,
|
||||
score = 200.0,
|
||||
snapshotAt = snapshotAt,
|
||||
randomTieBreaker = 0.8
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val snapshots = adapter.findSnapshots(RecommendedSectionType.CHEER_CREATOR, snapshotAt, offset = 0, limit = 10)
|
||||
|
||||
assertEquals(listOf(3L, 2L), snapshots.map { it.targetId })
|
||||
assertEquals(listOf(snapshotAt, snapshotAt), snapshots.map { it.snapshotAt })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldCheckSnapshotExistenceByExactSnapshotAtIncludingEmptyMarker() {
|
||||
val staleSnapshotAt = LocalDateTime.of(2026, 5, 28, 23, 59, 59)
|
||||
val expectedSnapshotAt = LocalDateTime.of(2026, 5, 29, 23, 59, 59)
|
||||
repository.save(
|
||||
snapshot(
|
||||
RecommendedSectionType.CHEER_CREATOR,
|
||||
targetId = 1L,
|
||||
score = 100.0,
|
||||
snapshotAt = staleSnapshotAt
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(false, adapter.existsSnapshot(RecommendedSectionType.CHEER_CREATOR, expectedSnapshotAt))
|
||||
|
||||
adapter.replaceSnapshots(RecommendedSectionType.CHEER_CREATOR, expectedSnapshotAt, emptyList())
|
||||
|
||||
assertEquals(true, adapter.existsSnapshot(RecommendedSectionType.CHEER_CREATOR, expectedSnapshotAt))
|
||||
assertEquals(
|
||||
emptyList<RecommendationSnapshotRecord>(),
|
||||
adapter.findSnapshots(RecommendedSectionType.CHEER_CREATOR, expectedSnapshotAt)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldReplaceSnapshotsByDeletingSameSectionSnapshotAtOnly() {
|
||||
val oldSnapshotAt = LocalDateTime.of(2026, 5, 28, 23, 59, 59)
|
||||
@@ -109,7 +164,7 @@ class RecommendationSnapshotPersistenceAdapterTest @Autowired constructor(
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldClearAiCharacterSectionSnapshotsWhenReplacingWithEmptySnapshots() {
|
||||
fun shouldSaveAiCharacterEmptySnapshotMarkerWhenReplacingWithEmptySnapshots() {
|
||||
val oldSnapshotAt = LocalDateTime.of(2026, 5, 28, 23, 59, 59)
|
||||
val snapshotAt = LocalDateTime.of(2026, 5, 29, 23, 59, 59)
|
||||
repository.saveAll(
|
||||
@@ -125,9 +180,10 @@ class RecommendationSnapshotPersistenceAdapterTest @Autowired constructor(
|
||||
assertEquals(listOf(2L), adapter.findLatestSnapshots(RecommendedSectionType.CHEER_CREATOR).map { it.targetId })
|
||||
assertEquals(true, adapter.existsLatestSnapshot(RecommendedSectionType.AI_CHARACTER))
|
||||
assertEquals(
|
||||
listOf(0L),
|
||||
listOf(1L, 0L),
|
||||
repository.findAll()
|
||||
.filter { it.sectionType == RecommendedSectionType.AI_CHARACTER }
|
||||
.sortedBy { it.snapshotAt }
|
||||
.map { it.targetId }
|
||||
)
|
||||
}
|
||||
@@ -142,6 +198,53 @@ class RecommendationSnapshotPersistenceAdapterTest @Autowired constructor(
|
||||
assertEquals(true, adapter.existsLatestSnapshot(RecommendedSectionType.AI_CHARACTER))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldSaveCheerCreatorEmptySnapshotMarkerWhenReplacingWithEmptySnapshots() {
|
||||
val oldSnapshotAt = LocalDateTime.of(2026, 5, 28, 23, 59, 59)
|
||||
val snapshotAt = LocalDateTime.of(2026, 5, 29, 23, 59, 59)
|
||||
repository.save(snapshot(RecommendedSectionType.CHEER_CREATOR, targetId = 1L, score = 100.0, snapshotAt = oldSnapshotAt))
|
||||
|
||||
adapter.replaceSnapshots(RecommendedSectionType.CHEER_CREATOR, snapshotAt, emptyList())
|
||||
|
||||
assertEquals(emptyList<RecommendationSnapshotRecord>(), adapter.findLatestSnapshots(RecommendedSectionType.CHEER_CREATOR))
|
||||
assertEquals(true, adapter.existsLatestSnapshot(RecommendedSectionType.CHEER_CREATOR))
|
||||
assertEquals(
|
||||
listOf(1L, 0L),
|
||||
repository.findAll()
|
||||
.filter { it.sectionType == RecommendedSectionType.CHEER_CREATOR }
|
||||
.sortedBy { it.snapshotAt }
|
||||
.map { it.targetId }
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldReplaceCheerCreatorEmptyMarkerWithRealSnapshots() {
|
||||
val snapshotAt = LocalDateTime.of(2026, 5, 29, 23, 59, 59)
|
||||
adapter.replaceSnapshots(RecommendedSectionType.CHEER_CREATOR, snapshotAt, emptyList())
|
||||
|
||||
adapter.replaceSnapshots(
|
||||
RecommendedSectionType.CHEER_CREATOR,
|
||||
snapshotAt,
|
||||
listOf(
|
||||
RecommendationSnapshotRecord(
|
||||
sectionType = RecommendedSectionType.CHEER_CREATOR,
|
||||
targetId = 9L,
|
||||
score = 90.0,
|
||||
snapshotAt = snapshotAt,
|
||||
randomTieBreaker = 0.9
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(listOf(9L), adapter.findLatestSnapshots(RecommendedSectionType.CHEER_CREATOR).map { it.targetId })
|
||||
assertEquals(
|
||||
listOf(9L),
|
||||
repository.findAll()
|
||||
.filter { it.sectionType == RecommendedSectionType.CHEER_CREATOR }
|
||||
.map { it.targetId }
|
||||
)
|
||||
}
|
||||
|
||||
private fun snapshot(
|
||||
sectionType: RecommendedSectionType,
|
||||
targetId: Long,
|
||||
|
||||
Reference in New Issue
Block a user