Skip to content

Commit

Permalink
YEL-214 [feat] 푸시알림 구현 및 unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjeongs committed Feb 28, 2024
1 parent 01f65ca commit 4b94592
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("지금이다! 날 짝사랑 하는 사람 보러가기")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -25,5 +23,5 @@ public interface NotificationService {

void sendOpenVoteNotification(User user);

void sendRecommendSignupNotification(User user);
void sendRecommendSignupAndGetTicketNotification(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -74,6 +75,19 @@ void init() {
.deletedAt(null).group(userGroup)
.groupAdmissionYear(19).email("[email protected]")
.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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4b94592

Please sign in to comment.