From 7c578972f77a40e27aa39efdeb7916bee9f2ad58 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 18 Sep 2026 14:21:35 +0900 Subject: [PATCH] =?UTF-8?q?fix(can):=20=ED=9A=8C=EC=9B=90=202=EC=9D=98=20?= =?UTF-8?q?=EA=B0=95=EC=A0=9C=20=ED=86=B5=ED=99=94=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=A0=9C=EA=B1=B0=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vividnext/sodalive/can/CanController.kt | 2 +- .../can/CanControllerIntegrationTest.kt | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/test/kotlin/kr/co/vividnext/sodalive/can/CanControllerIntegrationTest.kt diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt index 739f7807..6f464a10 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt @@ -17,7 +17,7 @@ class CanController(private val service: CanService) { fun getCans( @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? ): ApiResponse> { - val forcedCurrency = if (member != null && (member.id == 2L || member.id == 4L || member.id == 44144L)) { + val forcedCurrency = if (member != null && (member.id == 4L || member.id == 44144L)) { "JPY" } else { null diff --git a/src/test/kotlin/kr/co/vividnext/sodalive/can/CanControllerIntegrationTest.kt b/src/test/kotlin/kr/co/vividnext/sodalive/can/CanControllerIntegrationTest.kt new file mode 100644 index 00000000..1d8cb0c0 --- /dev/null +++ b/src/test/kotlin/kr/co/vividnext/sodalive/can/CanControllerIntegrationTest.kt @@ -0,0 +1,78 @@ +package kr.co.vividnext.sodalive.can + +import kr.co.vividnext.sodalive.common.CountryContext +import kr.co.vividnext.sodalive.member.Member +import kr.co.vividnext.sodalive.support.EmbeddedRedisInitializer +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.CsvSource +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.annotation.DirtiesContext +import org.springframework.test.context.ContextConfiguration +import org.springframework.transaction.annotation.Transactional +import java.math.BigDecimal +import javax.persistence.EntityManager + +@SpringBootTest(properties = ["spring.cache.type=none"]) +@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class]) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@Transactional +class CanControllerIntegrationTest @Autowired constructor( + private val controller: CanController, + private val countryContext: CountryContext, + private val entityManager: EntityManager +) { + @BeforeEach + fun setUp() { + listOf("KRW", "USD", "JPY").forEach { currency -> + entityManager.persist( + Can( + title = "test-$currency", + can = 100, + rewardCan = 0, + price = BigDecimal("100"), + currency = currency, + status = CanStatus.SALE + ) + ) + } + entityManager.flush() + entityManager.clear() + } + + @ParameterizedTest + @CsvSource( + "2, KR, KRW", + "2, US, USD", + "2, JP, USD", + "2, , USD", + "4, KR, JPY", + "4, US, JPY", + "44144, KR, JPY", + "44144, US, JPY", + "3, KR, KRW", + "3, US, USD", + ", KR, KRW", + ", US, USD", + ", , USD" + ) + @DisplayName("회원 2는 국가별 통화를 사용하고 기존 JPY 예외와 일반·비로그인 조회는 유지한다") + fun shouldSelectCurrencyByCountryExceptRemainingForcedMembers( + memberId: Long?, + countryCode: String?, + expectedCurrency: String + ) { + val member = memberId?.let { id -> + Member(nickname = "test-$id", password = "").apply { this.id = id } + } + countryContext.setCountryCode(countryCode) + + val response = controller.getCans(member) + + assertEquals(true, response.success) + assertEquals(listOf(expectedCurrency), response.data?.map { it.currency }) + } +}