fix(calculate): 관리자 정산 엑셀 다운로드를 스트리밍 방식으로 전환한다

This commit is contained in:
2026-03-05 12:21:57 +09:00
parent 07f8d22024
commit 6ac94174c8
8 changed files with 619 additions and 36 deletions

View File

@@ -6,10 +6,9 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.springframework.core.io.InputStreamResource
import org.springframework.data.domain.PageRequest
import org.springframework.http.HttpHeaders
import java.io.ByteArrayInputStream
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
class AdminChannelDonationCalculateControllerTest {
private lateinit var service: AdminChannelDonationCalculateService
@@ -135,6 +134,38 @@ class AdminChannelDonationCalculateControllerTest {
)
}
@Test
@DisplayName("관리자 컨트롤러는 날짜별 정산 엑셀을 다운로드한다")
fun shouldDownloadDateSettlementExcel() {
Mockito.`when`(
service.downloadChannelDonationByDateExcel(
startDateStr = "2026-02-01",
endDateStr = "2026-02-29"
)
).thenReturn(StreamingResponseBody { outputStream -> outputStream.write(byteArrayOf(1, 2, 3)) })
val response = controller.downloadChannelDonationByDateExcel(
startDateStr = "2026-02-01",
endDateStr = "2026-02-29"
)
assertEquals(200, response.statusCode.value())
val contentDispositionHeader = response.headers.getFirst(HttpHeaders.CONTENT_DISPOSITION)
assertNotNull(contentDispositionHeader)
assertEquals(true, contentDispositionHeader?.contains("attachment; filename*="))
assertEquals(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
response.headers.contentType.toString()
)
assertNotNull(response.body)
assertEquals(true, response.body is StreamingResponseBody)
Mockito.verify(service).downloadChannelDonationByDateExcel(
startDateStr = "2026-02-01",
endDateStr = "2026-02-29"
)
}
@Test
@DisplayName("관리자 컨트롤러는 크리에이터별 정산 엑셀을 다운로드한다")
fun shouldDownloadCreatorSettlementExcel() {
@@ -143,7 +174,7 @@ class AdminChannelDonationCalculateControllerTest {
startDateStr = "2026-02-01",
endDateStr = "2026-02-29"
)
).thenReturn(ByteArrayInputStream(byteArrayOf(1, 2, 3)))
).thenReturn(StreamingResponseBody { outputStream -> outputStream.write(byteArrayOf(1, 2, 3)) })
val response = controller.downloadChannelDonationByCreatorExcel(
startDateStr = "2026-02-01",
@@ -159,7 +190,7 @@ class AdminChannelDonationCalculateControllerTest {
response.headers.contentType.toString()
)
assertNotNull(response.body)
assertEquals(true, response.body is InputStreamResource)
assertEquals(true, response.body is StreamingResponseBody)
Mockito.verify(service).downloadChannelDonationByCreatorExcel(
startDateStr = "2026-02-01",

View File

@@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import java.io.ByteArrayOutputStream
class AdminChannelDonationCalculateServiceTest {
private lateinit var repository: AdminChannelDonationCalculateQueryRepository
@@ -153,6 +154,54 @@ class AdminChannelDonationCalculateServiceTest {
)
}
@Test
@DisplayName("관리자 날짜별 정산 엑셀 다운로드는 xlsx 바이트를 생성한다")
fun shouldGenerateDateSettlementExcelBytes() {
Mockito.`when`(
repository.getChannelDonationByDateTotalCount(
"2026-02-20".convertLocalDateTime(),
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59)
)
).thenReturn(1)
Mockito.`when`(
repository.getChannelDonationByDate(
"2026-02-20".convertLocalDateTime(),
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59),
0L,
1L
)
).thenReturn(
listOf(
GetAdminChannelDonationSettlementQueryData(
date = "2026-02-20",
creator = "creator-a",
count = 3L,
totalCan = 100
)
)
)
val response = service.downloadChannelDonationByDateExcel(
startDateStr = "2026-02-20",
endDateStr = "2026-02-21"
)
val outputStream = ByteArrayOutputStream()
response.writeTo(outputStream)
assertTrue(outputStream.toByteArray().isNotEmpty())
Mockito.verify(repository).getChannelDonationByDateTotalCount(
"2026-02-20".convertLocalDateTime(),
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59)
)
Mockito.verify(repository).getChannelDonationByDate(
"2026-02-20".convertLocalDateTime(),
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59),
0L,
1L
)
}
@Test
@DisplayName("관리자 크리에이터별 정산 엑셀 다운로드는 xlsx 바이트를 생성한다")
fun shouldGenerateCreatorSettlementExcelBytes() {
@@ -175,8 +224,10 @@ class AdminChannelDonationCalculateServiceTest {
startDateStr = "2026-02-20",
endDateStr = "2026-02-21"
)
val outputStream = ByteArrayOutputStream()
response.writeTo(outputStream)
assertTrue(response.readAllBytes().isNotEmpty())
assertTrue(outputStream.toByteArray().isNotEmpty())
Mockito.verify(repository).getChannelDonationByCreatorForExcel(
"2026-02-20".convertLocalDateTime(),