feat(ranking): 주간 랭킹 기간 정책을 추가한다

This commit is contained in:
2026-06-08 15:23:08 +09:00
parent 250bebb93b
commit 5019c32145
2 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
package kr.co.vividnext.sodalive.v2.ranking.domain
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
class CreatorRankingPeriodPolicyTest {
private val policy = CreatorRankingPeriodPolicy()
@Test
@DisplayName("월요일 KST 기준 지난 주 월요일 00시 이상 이번 주 월요일 00시 미만 기간을 산출한다")
fun shouldResolveLastCompletedWeekByKstMonday() {
val now = ZonedDateTime.of(2026, 6, 8, 6, 0, 0, 0, ZoneId.of("Asia/Seoul"))
val period = policy.resolveLastCompletedWeek(now)
assertEquals(LocalDateTime.of(2026, 6, 1, 0, 0), period.startInclusiveKst)
assertEquals(LocalDateTime.of(2026, 6, 8, 0, 0), period.endExclusiveKst)
}
@Test
@DisplayName("기간 산출은 서버 timezone UTC와 무관하게 KST 기준으로 계산한다")
fun shouldResolveLastCompletedWeekIndependentOfServerTimezone() {
val now = ZonedDateTime.of(2026, 6, 7, 21, 0, 0, 0, ZoneId.of("UTC"))
val period = policy.resolveLastCompletedWeek(now)
assertEquals(LocalDateTime.of(2026, 6, 1, 0, 0), period.startInclusiveKst)
assertEquals(LocalDateTime.of(2026, 6, 8, 0, 0), period.endExclusiveKst)
}
@Test
@DisplayName("연도 경계를 넘어도 KST 기준 지난 완료 주차를 산출한다")
fun shouldResolveLastCompletedWeekAcrossYearBoundary() {
val now = ZonedDateTime.of(2026, 1, 1, 12, 0, 0, 0, ZoneId.of("Asia/Seoul"))
val period = policy.resolveLastCompletedWeek(now)
assertEquals(LocalDateTime.of(2025, 12, 22, 0, 0), period.startInclusiveKst)
assertEquals(LocalDateTime.of(2025, 12, 29, 0, 0), period.endExclusiveKst)
}
@Test
@DisplayName("KST 기간은 DB 조회용 UTC LocalDateTime 이상/미만 조건으로 변환한다")
fun shouldConvertKstPeriodToUtcRange() {
val period = CreatorRankingPeriod(
startInclusiveKst = LocalDateTime.of(2026, 6, 1, 0, 0),
endExclusiveKst = LocalDateTime.of(2026, 6, 8, 0, 0)
)
val utcRange = policy.toUtcRange(period)
assertEquals(LocalDateTime.of(2026, 5, 31, 15, 0), utcRange.startInclusiveUtc)
assertEquals(LocalDateTime.of(2026, 6, 7, 15, 0), utcRange.endExclusiveUtc)
}
}