diff --git a/docs/20260225_채널후원메시지_캔_천단위콤마추가.md b/docs/20260225_채널후원메시지_캔_천단위콤마추가.md new file mode 100644 index 00000000..ab188846 --- /dev/null +++ b/docs/20260225_채널후원메시지_캔_천단위콤마추가.md @@ -0,0 +1,21 @@ +# 20260225_채널후원메시지_캔_천단위콤마추가 + +## 구현 항목 +- [x] `ChannelDonationService.kt`의 `buildMessage` 함수 수정 (캔 수량 천단위 콤마 추가) +- [x] 관련 테스트 코드를 통한 검증 + +## 검증 기록 +### 1차 구현 +- **무엇을**: `buildMessage` 함수 내에서 `can` 변수를 `String.format("%,d", can)`으로 포맷팅하도록 수정 +- **왜**: 후원 메시지 표시 시 캔 수량에 천단위 콤마를 추가하여 가독성을 높이기 위함 +- **어떻게**: + - `ChannelDonationService.kt` 수정 + - `./gradlew test` 실행 후 결과 확인 + +### 2차 수정 +- **무엇을**: `ChannelDonationServiceTest`에 `can = 1000`일 때 메시지가 `1,000캔` 형식으로 생성되는지 검증하는 테스트(`shouldFormatCanWithCommaInDonationMessage`)를 추가하고 문서 체크박스를 완료 처리 +- **왜**: 기존 테스트는 천단위 콤마 포맷을 직접 검증하지 않아 문서의 "관련 테스트 코드를 통한 검증" 항목을 충족하기 어려웠기 때문 +- **어떻게**: + - `src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationServiceTest.kt`에 메시지 포맷 검증 테스트 추가 + - `./gradlew test --tests "kr.co.vividnext.sodalive.explorer.profile.channelDonation.ChannelDonationServiceTest"` 실행: 성공 + - `./gradlew build` 실행: 성공 diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationService.kt index d6cba758..d1006170 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationService.kt @@ -117,7 +117,8 @@ class ChannelDonationService( } else { "explorer.channel_donation.message.default.public" } - val defaultMessage = getMessage(key, can) + val formattedCan = String.format("%,d", can) + val defaultMessage = getMessage(key, formattedCan) return if (additionalMessage.isNullOrBlank()) { defaultMessage diff --git a/src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationControllerTest.kt b/src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationControllerTest.kt index 79ecd128..3babff1a 100644 --- a/src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationControllerTest.kt +++ b/src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationControllerTest.kt @@ -59,9 +59,9 @@ class ChannelDonationControllerTest { memberId = member.id!!, nickname = member.nickname, profileUrl = "https://cdn.test/profile/default-profile.png", - can = 3, + can = 1000, isSecret = false, - message = "3캔을 후원하셨습니다.", + message = "1,000캔을 후원하셨습니다.", createdAt = "2026-02-23T09:30:00" ) val response = GetChannelDonationListResponse(totalCount = 1, items = listOf(item)) diff --git a/src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationServiceTest.kt b/src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationServiceTest.kt index e3d86771..d9705cb0 100644 --- a/src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationServiceTest.kt +++ b/src/test/kotlin/kr/co/vividnext/sodalive/explorer/profile/channelDonation/ChannelDonationServiceTest.kt @@ -110,6 +110,46 @@ class ChannelDonationServiceTest { ) } + @Test + fun shouldFormatCanWithCommaInDonationMessage() { + val creator = createMember(id = 1L, role = MemberRole.CREATOR, nickname = "creator") + val viewer = createMember(id = 2L, role = MemberRole.USER, nickname = "viewer") + val message = ChannelDonationMessage(can = 1000, isSecret = true, additionalMessage = "응원합니다") + message.id = 1001L + message.member = viewer + message.creator = creator + message.createdAt = LocalDateTime.of(2026, 2, 20, 12, 0, 0) + + Mockito.`when`(memberRepository.findCreatorByIdOrNull(creator.id!!)).thenReturn(creator) + Mockito.`when`( + channelDonationMessageRepository.getChannelDonationMessageTotalCount( + Mockito.eq(creator.id!!), + Mockito.eq(viewer.id!!), + Mockito.eq(false), + anyLocalDateTime() + ) + ).thenReturn(1) + Mockito.`when`( + channelDonationMessageRepository.getChannelDonationMessageList( + Mockito.eq(creator.id!!), + Mockito.eq(viewer.id!!), + Mockito.eq(false), + Mockito.eq(0L), + Mockito.eq(5L), + anyLocalDateTime() + ) + ).thenReturn(listOf(message)) + + val result = service.getChannelDonationList( + creatorId = creator.id!!, + member = viewer, + offset = 0, + limit = 5 + ) + + assertEquals("1,000캔을 비밀후원하셨습니다.\n\"응원합니다\"", result.items[0].message) + } + @Test fun shouldPassCreatorVisibilityFlagToRepositoryWhenRequesterIsCreatorSelf() { val creator = createMember(id = 1L, role = MemberRole.CREATOR, nickname = "creator")