refactor(charge): 충전 이벤트 작업 패키지를 정리한다

This commit is contained in:
2026-05-18 13:46:26 +09:00
parent 810b143c9e
commit 56acf257e0
11 changed files with 22 additions and 21 deletions
@@ -1,73 +0,0 @@
package kr.co.vividnext.sodalive.admin.event.charge
import kr.co.vividnext.sodalive.can.charge.event.ChargeEventJob
import kr.co.vividnext.sodalive.can.charge.event.ChargeEventJobRepository
import kr.co.vividnext.sodalive.can.charge.event.ChargeEventJobStatus
import kr.co.vividnext.sodalive.can.charge.event.ChargeEventJobType
import kr.co.vividnext.sodalive.can.payment.PaymentGateway
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import java.time.LocalDateTime
class AdminChargeEventJobServiceTest {
@Test
fun shouldReturnOnlyPendingAndFailedJobs() {
val repository = Mockito.mock(ChargeEventJobRepository::class.java)
val service = AdminChargeEventJobService(repository)
val pending = job(1L, ChargeEventJobStatus.PENDING)
val failed = job(2L, ChargeEventJobStatus.FAILED)
Mockito.`when`(repository.findVisibleAdminJobs()).thenReturn(listOf(pending, failed))
val responses = service.getJobs()
assertEquals(listOf(1L, 2L), responses.map { it.id })
assertEquals(listOf(ChargeEventJobStatus.PENDING, ChargeEventJobStatus.FAILED), responses.map { it.status })
}
@Test
fun shouldRetryOnlyFailedJob() {
val repository = Mockito.mock(ChargeEventJobRepository::class.java)
val service = AdminChargeEventJobService(repository)
val failed = job(1L, ChargeEventJobStatus.FAILED)
Mockito.`when`(repository.findByIdForUpdate(1L)).thenReturn(failed)
service.retry(1L)
assertEquals(ChargeEventJobStatus.PENDING, failed.status)
assertEquals(0, failed.retryCount)
}
@Test
fun shouldNotChangeNonFailedJobOnRetryRequest() {
val repository = Mockito.mock(ChargeEventJobRepository::class.java)
val service = AdminChargeEventJobService(repository)
val pending = job(1L, ChargeEventJobStatus.PENDING)
Mockito.`when`(repository.findByIdForUpdate(1L)).thenReturn(pending)
service.retry(1L)
assertEquals(ChargeEventJobStatus.PENDING, pending.status)
assertEquals(2, pending.retryCount)
}
private fun job(id: Long, status: ChargeEventJobStatus): ChargeEventJob {
return ChargeEventJob(
sourceChargeId = 100L,
memberId = 10L,
chargeEventId = 20L,
jobType = ChargeEventJobType.ACTIVE_CHARGE_EVENT,
idempotencyKey = "charge-event:100:ACTIVE_CHARGE_EVENT:20",
additionalCan = 10,
paymentGateway = PaymentGateway.PG,
container = "pg",
methodSnapshot = "봄 이벤트",
status = status,
retryCount = 2,
nextRetryAt = LocalDateTime.now()
).also { it.id = id }
}
}