fix(fcm): 시스템 카테고리 알림 저장 제외 정책을 서비스에 반영한다

This commit is contained in:
2026-03-13 22:57:37 +09:00
parent 205cfe0899
commit 7251939107
3 changed files with 59 additions and 2 deletions

View File

@@ -79,7 +79,7 @@ class ChargeEventService(
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.INDIVIDUAL,
category = PushNotificationCategory.MESSAGE,
category = PushNotificationCategory.SYSTEM,
title = chargeEvent.title,
messageKey = "can.charge.event.additional_can_paid",
args = listOf(additionalCan),
@@ -103,7 +103,7 @@ class ChargeEventService(
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.INDIVIDUAL,
category = PushNotificationCategory.MESSAGE,
category = PushNotificationCategory.SYSTEM,
titleKey = "can.charge.event.first_title",
messageKey = "can.charge.event.additional_can_paid",
args = listOf(additionalCan),

View File

@@ -48,6 +48,7 @@ class PushNotificationService(
if (recipientMemberIds.isEmpty()) return
val category = resolveCategory(fcmEvent) ?: return
if (category == PushNotificationCategory.SYSTEM) return
val senderSnapshot = resolveSenderSnapshot(fcmEvent)
val deepLink = FcmService.buildDeepLink(
serverEnv = serverEnv,

View File

@@ -78,6 +78,62 @@ class PushNotificationServiceTest {
Mockito.verify(pushNotificationListRepository, Mockito.never()).save(Mockito.any(PushNotificationList::class.java))
}
@Test
fun shouldNotSaveWhenResolvedCategoryIsSystem() {
// given: 이벤트 category가 null이고 타입 기반 보정 결과가 SYSTEM인 상황을 준비한다.
val event = FcmEvent(
type = FcmEventType.INDIVIDUAL,
category = null,
recipients = listOf(1L)
)
val pushTokens = listOf(PushTokenInfo(token = "token-1", deviceType = "aos", languageCode = "ko"))
Mockito.`when`(pushTokenRepository.findMemberIdsByTokenIn(listOf("token-1"))).thenReturn(listOf(1L))
// when: 알림 적재를 실행한다.
service.saveNotification(
fcmEvent = event,
languageCode = "ko",
translatedMessage = "시스템 알림",
recipientPushTokens = pushTokens
)
// then: SYSTEM 카테고리 보정 결과에 따라 저장이 발생하지 않아야 한다.
Mockito.verify(pushNotificationListRepository, Mockito.never()).save(Mockito.any(PushNotificationList::class.java))
}
@Test
fun shouldSaveWhenCategoryIsNullAndResolvedCategoryIsNonSystem() {
// given: 이벤트 category가 null이어도 타입 기반 보정 결과가 LIVE면 저장되어야 한다.
val event = FcmEvent(
type = FcmEventType.START_LIVE,
category = null,
roomId = 11L,
creatorId = 20L,
deepLinkValue = FcmDeepLinkValue.LIVE,
deepLinkId = 11L
)
val pushTokens = listOf(PushTokenInfo(token = "token-a", deviceType = "aos", languageCode = "ko"))
Mockito.`when`(pushTokenRepository.findMemberIdsByTokenIn(listOf("token-a"))).thenReturn(listOf(10L))
Mockito.`when`(pushNotificationListRepository.save(Mockito.any(PushNotificationList::class.java)))
.thenAnswer { invocation -> invocation.getArgument(0) }
// when: 알림 적재를 실행한다.
service.saveNotification(
fcmEvent = event,
languageCode = "ko",
translatedMessage = "라이브가 시작되었습니다.",
recipientPushTokens = pushTokens
)
// then: 보정된 LIVE 카테고리로 저장되어야 한다.
val captor = ArgumentCaptor.forClass(PushNotificationList::class.java)
Mockito.verify(pushNotificationListRepository).save(captor.capture())
val saved = captor.value
assertEquals(PushNotificationCategory.LIVE, saved.category)
}
@Test
fun shouldSaveChunkedRecipientsAndSenderSnapshotWhenEventIsValid() {
// given: 1001명의 수신자를 가진 유효 이벤트를 준비한다.