Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.eatssu.android.domain.model.Partnership
import com.eatssu.common.enums.PeriodType
import java.time.LocalDate

private val FESTIVAL_START_DATE: LocalDate = LocalDate.of(2026, 9, 15)
private val FESTIVAL_START_DATE: LocalDate = LocalDate.of(2026, 9, 14)
private val FESTIVAL_END_DATE: LocalDate = LocalDate.of(2026, 9, 16)

internal fun isFestivalPartnershipPeriod(date: LocalDate): Boolean =
Expand All @@ -18,7 +18,7 @@ internal fun activeFestivalPartnerships(

return partnerships.mapNotNull { partnership ->
val activeFestivalInfos = partnership.partnershipInfos.filter { info ->
info.periodType == PeriodType.FESTIVAL && info.isActiveOn(date)
info.periodType == PeriodType.FESTIVAL && info.isVisibleOn(date)
}

partnership
Expand Down Expand Up @@ -53,10 +53,13 @@ internal fun mergePartnerships(
internal val Partnership.hasFestivalPartnership: Boolean
get() = partnershipInfos.any { it.periodType == PeriodType.FESTIVAL }

private fun Partnership.PartnershipInfo.isActiveOn(date: LocalDate): Boolean {
private fun Partnership.PartnershipInfo.isVisibleOn(date: LocalDate): Boolean {
val start = startDate.toLocalDateOrNull() ?: return false
val end = endDate.toLocalDateOrNull() ?: return false
return !date.isBefore(start) && !date.isAfter(end)
if (start.isAfter(FESTIVAL_END_DATE) || end.isBefore(FESTIVAL_START_DATE)) return false

val visibleStart = minOf(start, FESTIVAL_START_DATE)
return !date.isBefore(visibleStart) && !date.isAfter(end)
}

private fun String.toLocalDateOrNull(): LocalDate? = runCatching(LocalDate::parse).getOrNull()
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class FestivalPartnershipPolicySpec : AppBehaviorSpec({
infos = listOf(normalInfo, festivalInfo),
)

`when`("행사 시작 전이거나 종료 후이면") {
`when`("사전 노출 시작 전이거나 축제 종료 후이면") {
then("축제 제휴를 노출하지 않는다") {
activeFestivalPartnerships(
partnerships = listOf(source),
date = LocalDate.of(2026, 9, 14),
date = LocalDate.of(2026, 9, 13),
) shouldBe emptyList()
activeFestivalPartnerships(
partnerships = listOf(source),
Expand All @@ -46,9 +46,10 @@ class FestivalPartnershipPolicySpec : AppBehaviorSpec({
}
}

`when`("9월 15일 또는 16일이면") {
`when`("9월 14일부터 16일까지이면") {
then("FESTIVAL 타입인 제휴만 노출한다") {
listOf(
LocalDate.of(2026, 9, 14),
LocalDate.of(2026, 9, 15),
LocalDate.of(2026, 9, 16),
).forEach { date ->
Expand Down
Loading