From 4b94592aef030545d7de916ebadeebe0b039f8fa Mon Sep 17 00:00:00 2001 From: hyeonjeongs Date: Wed, 28 Feb 2024 10:54:19 +0900 Subject: [PATCH] =?UTF-8?q?YEL-214=20[feat]=20=ED=91=B8=EC=8B=9C=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20unit=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authorization/service/AuthService.java | 2 +- .../domain/vote/service/VoteService.java | 2 +- .../dto/request/NotificationMessage.java | 2 +- .../service/NotificationFcmService.java | 12 +++---- .../firebase/service/NotificationService.java | 4 +-- .../firebase/NotificationFcmServiceTest.java | 36 ++++++++++++++++++- 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/yello/server/domain/authorization/service/AuthService.java b/src/main/java/com/yello/server/domain/authorization/service/AuthService.java index 709ec931..d995dd79 100644 --- a/src/main/java/com/yello/server/domain/authorization/service/AuthService.java +++ b/src/main/java/com/yello/server/domain/authorization/service/AuthService.java @@ -127,7 +127,7 @@ public void recommendUser(String recommendYelloId, String userYelloId) { ZonedDateTime.now(GlobalZoneId).format(ISO_OFFSET_DATE_TIME), recommendedUser )); - notificationService.sendRecommendSignupNotification(recommendedUser); + notificationService.sendRecommendSignupAndGetTicketNotification(recommendedUser); } notificationService.sendRecommendNotification(user, recommendedUser); diff --git a/src/main/java/com/yello/server/domain/vote/service/VoteService.java b/src/main/java/com/yello/server/domain/vote/service/VoteService.java index 246aef58..afcdc96a 100644 --- a/src/main/java/com/yello/server/domain/vote/service/VoteService.java +++ b/src/main/java/com/yello/server/domain/vote/service/VoteService.java @@ -107,7 +107,7 @@ public VoteDetailResponse findVoteById(Long voteId, Long userId) { final User user = userRepository.getById(userId); if(!vote.getIsRead()) { - notificationService.sendOpenVoteNotification(user); + notificationService.sendOpenVoteNotification(vote.getSender()); } vote.read(); diff --git a/src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.java b/src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.java index 44f0ccdc..00b0204f 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.java @@ -60,7 +60,7 @@ public static NotificationMessage toUserOpenVoteNotificationContent(User user) { .build(); } - public static NotificationMessage toUserAndFriendRecommendSignupNotificationContent(User user) { + public static NotificationMessage toUserAndFriendRecommendSignupAndGetTicketNotificationContent(User user) { return NotificationMessage.builder() .title(MessageFormat.format("{0}님이 나를 추천인으로 가입해 열람권이 지급됐어요!", user.getName())) .message("지금이다! 날 짝사랑 하는 사람 보러가기") diff --git a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java index f6939020..58aa485c 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java @@ -135,21 +135,21 @@ public void sendLunchEventNotification(User user) { } @Override - public void sendOpenVoteNotification(User user) { + public void sendOpenVoteNotification(User sender) { NotificationMessage notificationMessage = - NotificationMessage.toUserOpenVoteNotificationContent(user); + NotificationMessage.toUserOpenVoteNotificationContent(sender); - if (user.getDeviceToken() != null && !Objects.equals(user.getDeviceToken(), "")) { + if (sender.getDeviceToken() != null && !Objects.equals(sender.getDeviceToken(), "")) { final Message message = - fcmManager.createMessage(user.getDeviceToken(), notificationMessage); + fcmManager.createMessage(sender.getDeviceToken(), notificationMessage); fcmManager.send(message); } } @Override - public void sendRecommendSignupNotification(User recommendUser) { + public void sendRecommendSignupAndGetTicketNotification(User recommendUser) { NotificationMessage notificationMessage = - NotificationMessage.toUserAndFriendRecommendSignupNotificationContent(recommendUser); + NotificationMessage.toUserAndFriendRecommendSignupAndGetTicketNotificationContent(recommendUser); if (recommendUser.getDeviceToken() != null && !Objects.equals(recommendUser.getDeviceToken(), "")) { final Message message = diff --git a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java index 83a5bd07..e613b4aa 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java @@ -6,8 +6,6 @@ import com.yello.server.global.common.dto.EmptyObject; import com.yello.server.infrastructure.firebase.dto.request.NotificationCustomMessage; -import java.util.List; - public interface NotificationService { void sendRecommendNotification(User user, User target); @@ -25,5 +23,5 @@ public interface NotificationService { void sendOpenVoteNotification(User user); - void sendRecommendSignupNotification(User user); + void sendRecommendSignupAndGetTicketNotification(User user); } diff --git a/src/test/java/com/yello/server/infrastructure/firebase/NotificationFcmServiceTest.java b/src/test/java/com/yello/server/infrastructure/firebase/NotificationFcmServiceTest.java index 9cde6837..a650f5b1 100644 --- a/src/test/java/com/yello/server/infrastructure/firebase/NotificationFcmServiceTest.java +++ b/src/test/java/com/yello/server/infrastructure/firebase/NotificationFcmServiceTest.java @@ -36,7 +36,8 @@ class NotificationFcmServiceTest { private User user; private User target; private User dummy; - + private Vote vote; + private Question question; @BeforeEach void init() { this.notificationService = NotificationFcmService.builder() @@ -74,6 +75,19 @@ void init() { .deletedAt(null).group(userGroup) .groupAdmissionYear(19).email("yello@test.com") .build(); + question = Question.builder() + .id(1L) + .nameHead(null).nameFoot("와") + .keywordHead("멋진").keywordFoot("에서 놀고싶어") + .build(); + vote = Vote.builder() + .id(1L) + .colorIndex(0).answer("test") + .isRead(false).nameHint(-1).isAnswerRevealed(false) + .sender(userRepository.getById(1L)) + .receiver(userRepository.getById(2L)) + .question(question).createdAt(LocalDateTime.now()) + .build(); } @Test @@ -120,6 +134,26 @@ void init() { notificationService.sendFriendNotification(friend); } + @Test + void 친구가_내가_보낸_쪽지_열람시_알림_전송에_성공합니다() { + //given + target.setDeviceToken("test-device-token"); + + // when + // then + notificationService.sendOpenVoteNotification(vote.getSender()); + } + + @Test + void 추천인_코드_가입하여_열람권_얻은_경우_알림_전송에_성공합니다() { + //given + target.setDeviceToken("test-device-token"); + + // when + // then + notificationService.sendRecommendSignupAndGetTicketNotification(target); + } + @Test void 푸시_알림_전송_시_존재하지_않는_유저인_경우에_UserNotFoundException이_발생합니다() { // given