From 9d1098e0edf3d9fd1502c9ccaac7f7a1e0a4fe59 Mon Sep 17 00:00:00 2001 From: gs97ahn Date: Thu, 15 Feb 2024 01:10:26 +0900 Subject: [PATCH] [FEAT] deepLink add to fcm and notification --- .../response/DeepLinkResponse.java | 8 +- .../response/NotificationPageResponse.java | 14 +- .../notification/NotificationService.java | 80 +++++---- .../notification/DeepLinkType.java} | 8 +- .../domain/notification/Notification.java | 14 +- .../domain/notification/NotificationType.java | 20 --- src/main/resources/schema.sql | 2 +- .../notification/NotificationServiceTest.java | 169 ++++++++++-------- .../domain/notification/DeepLinkTypeTest.java | 65 +++++++ .../domain/notification/NotificationTest.java | 49 +++-- .../notification/NotificationTypeTest.java | 71 -------- .../NotificationRepositoryTest.java | 32 ++-- 12 files changed, 263 insertions(+), 269 deletions(-) rename src/main/java/com/gabojait/gabojaitspring/{common/constant/deepLink/DeepLink.java => domain/notification/DeepLinkType.java} (76%) delete mode 100644 src/main/java/com/gabojait/gabojaitspring/domain/notification/NotificationType.java create mode 100644 src/test/java/com/gabojait/gabojaitspring/domain/notification/DeepLinkTypeTest.java delete mode 100644 src/test/java/com/gabojait/gabojaitspring/domain/notification/NotificationTypeTest.java diff --git a/src/main/java/com/gabojait/gabojaitspring/api/dto/notification/response/DeepLinkResponse.java b/src/main/java/com/gabojait/gabojaitspring/api/dto/notification/response/DeepLinkResponse.java index ee9bcc24..ee5b9a89 100644 --- a/src/main/java/com/gabojait/gabojaitspring/api/dto/notification/response/DeepLinkResponse.java +++ b/src/main/java/com/gabojait/gabojaitspring/api/dto/notification/response/DeepLinkResponse.java @@ -1,6 +1,6 @@ package com.gabojait.gabojaitspring.api.dto.notification.response; -import com.gabojait.gabojaitspring.common.constant.deepLink.DeepLink; +import com.gabojait.gabojaitspring.domain.notification.DeepLinkType; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; @@ -17,8 +17,8 @@ public class DeepLinkResponse { @ApiModelProperty(position = 2, required = true, value = "설명") private String description; - public DeepLinkResponse(DeepLink deepLink) { - this.url = deepLink.getUrl(); - this.description = deepLink.getDescription(); + public DeepLinkResponse(DeepLinkType deepLinkType) { + this.description = deepLinkType.getDescription(); + this.url = deepLinkType.getUrl(); } } diff --git a/src/main/java/com/gabojait/gabojaitspring/api/dto/notification/response/NotificationPageResponse.java b/src/main/java/com/gabojait/gabojaitspring/api/dto/notification/response/NotificationPageResponse.java index 9b10c903..25126c1b 100644 --- a/src/main/java/com/gabojait/gabojaitspring/api/dto/notification/response/NotificationPageResponse.java +++ b/src/main/java/com/gabojait/gabojaitspring/api/dto/notification/response/NotificationPageResponse.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.gabojait.gabojaitspring.domain.notification.Notification; -import com.gabojait.gabojaitspring.domain.notification.NotificationType; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; @@ -18,19 +17,16 @@ public class NotificationPageResponse { @ApiModelProperty(position = 1, required = true, value = "알림 식별자") private Long notificationId; - @ApiModelProperty(position = 2, required = true, value = "알림 타입") - private NotificationType notificationType; - - @ApiModelProperty(position = 3, required = true, value = "알림 제목") + @ApiModelProperty(position = 2, required = true, value = "알림 제목") private String title; - @ApiModelProperty(position = 4, required = true, value = "알림 내용") + @ApiModelProperty(position = 3, required = true, value = "알림 내용") private String body; - @ApiModelProperty(position = 5, required = true, value = "읽음 여부") + @ApiModelProperty(position = 4, required = true, value = "읽음 여부") private Boolean isRead; - @ApiModelProperty(position = 6, required = true, value = "딥링크") + @ApiModelProperty(position = 5, required = true, value = "딥링크") private DeepLinkResponse deepLink; @ApiModelProperty(position = 6, required = true, value = "생성일") @@ -43,10 +39,10 @@ public class NotificationPageResponse { public NotificationPageResponse(Notification notification) { this.notificationId = notification.getId(); - this.notificationType = notification.getNotificationType(); this.title = notification.getTitle(); this.body = notification.getBody(); this.isRead = notification.getIsRead(); + this.deepLink = new DeepLinkResponse(notification.getDeepLinkType()); this.createdAt = notification.getCreatedAt(); this.updatedAt = notification.getUpdatedAt(); } diff --git a/src/main/java/com/gabojait/gabojaitspring/api/service/notification/NotificationService.java b/src/main/java/com/gabojait/gabojaitspring/api/service/notification/NotificationService.java index 53eead8d..04334036 100644 --- a/src/main/java/com/gabojait/gabojaitspring/api/service/notification/NotificationService.java +++ b/src/main/java/com/gabojait/gabojaitspring/api/service/notification/NotificationService.java @@ -1,9 +1,9 @@ package com.gabojait.gabojaitspring.api.service.notification; -import com.gabojait.gabojaitspring.common.response.PageData; import com.gabojait.gabojaitspring.api.dto.notification.response.NotificationPageResponse; +import com.gabojait.gabojaitspring.common.response.PageData; +import com.gabojait.gabojaitspring.domain.notification.DeepLinkType; import com.gabojait.gabojaitspring.domain.notification.Notification; -import com.gabojait.gabojaitspring.domain.notification.NotificationType; import com.gabojait.gabojaitspring.domain.offer.Offer; import com.gabojait.gabojaitspring.domain.team.Team; import com.gabojait.gabojaitspring.domain.team.TeamMember; @@ -82,11 +82,11 @@ public void sendTeamMemberJoin(Offer offer) { String userBody = offer.getPosition().getText() + "로서 역량을 펼쳐보세요!"; String teamTitle = "새로운 " + offer.getPosition().getText() + " 합류"; String teamBody = user.getNickname() + "님이 " + offer.getPosition().getText() + "로 팀에 합류하였어요."; - NotificationType notificationType = NotificationType.NEW_TEAM_MEMBER; + DeepLinkType deepLinkType = DeepLinkType.TEAM_PAGE; - createAndSaveNotification(user, notificationType, userTitle, userBody); + createAndSaveNotification(user, userTitle, userBody, deepLinkType); if (!userFcms.isEmpty()) { - Map data = createFcmData(userTitle, userBody, notificationType); + Map data = createFcmData(userTitle, userBody, deepLinkType.getUrl()); MulticastMessage message = createMulticast(userFcms, data); sendMulticast(message); @@ -94,10 +94,10 @@ public void sendTeamMemberJoin(Offer offer) { teamMemberRepository.findAllExceptUserFetchUser(team.getId(), user.getId()) .forEach(teamMember -> - createAndSaveNotification(teamMember.getUser(), notificationType, teamTitle, teamBody) + createAndSaveNotification(teamMember.getUser(), teamTitle, teamBody, deepLinkType) ); if (!teamFcms.isEmpty()) { - Map data = createFcmData(teamTitle, teamBody, notificationType); + Map data = createFcmData(teamTitle, teamBody, deepLinkType.getUrl()); MulticastMessage message = createMulticast(teamFcms, data); sendMulticast(message); @@ -116,13 +116,14 @@ public void sendTeamMemberFired(User user, Team team) { String userTitle = team.getProjectName() + "팀에서 추방"; String userBody = team.getProjectName() + "팀에서 추방 되었어요. 아쉽지만 새로운 팀을 찾아보세요."; + DeepLinkType userDeepLinkType = DeepLinkType.HOME_PAGE; String teamTitle = user.getNickname() + "님 팀에서 추방"; String teamBody = user.getNickname() + "님이 팀장에 의해 추방되었어요."; - NotificationType notificationType = NotificationType.FIRED_TEAM_MEMBER; + DeepLinkType teamDeepLinkType = DeepLinkType.TEAM_PAGE; - createAndSaveNotification(user, notificationType, userTitle, userBody); + createAndSaveNotification(user, userTitle, userBody, userDeepLinkType); if (!userFcms.isEmpty()) { - Map data = createFcmData(userTitle, userBody, notificationType); + Map data = createFcmData(userTitle, userBody, userDeepLinkType.getUrl()); MulticastMessage message = createMulticast(userFcms, data); sendMulticast(message); @@ -130,10 +131,10 @@ public void sendTeamMemberFired(User user, Team team) { teamMemberRepository.findAllExceptUserFetchUser(team.getId(), user.getId()) .forEach(teamMember -> - createAndSaveNotification(teamMember.getUser(), notificationType, teamTitle, teamBody) + createAndSaveNotification(teamMember.getUser(), teamTitle, teamBody, teamDeepLinkType) ); if (!teamFcms.isEmpty()) { - Map data = createFcmData(teamTitle, teamBody, notificationType); + Map data = createFcmData(teamTitle, teamBody, teamDeepLinkType.getUrl()); MulticastMessage message = createMulticast(teamFcms, data); sendMulticast(message); @@ -151,13 +152,13 @@ public void sendTeamMemberQuit(User user, Team team) { String title = user.getNickname() + "님 팀 탈퇴"; String body = user.getNickname() + "님이 팀에서 탈퇴하였습니다."; - NotificationType notificationType = NotificationType.QUIT_TEAM_MEMBER; + DeepLinkType deepLinkType = DeepLinkType.TEAM_PAGE; teamMemberRepository.findAllExceptUserFetchUser(team.getId(), user.getId()) .forEach(teamMember -> - createAndSaveNotification(teamMember.getUser(), notificationType, title, body) + createAndSaveNotification(teamMember.getUser(), title, body, deepLinkType) ); if (!fcms.isEmpty()) { - Map data = createFcmData(title, body, notificationType); + Map data = createFcmData(title, body, deepLinkType.getUrl()); MulticastMessage message = createMulticast(fcms, data); sendMulticast(message); @@ -173,14 +174,14 @@ public void sendTeamMemberQuit(User user, Team team) { public void sendTeamIncomplete(Team team) { List fcms = fcmRepository.findAllTeam(team.getId()); String title = team.getProjectName() + "팀 해산"; - String boy = "아쉽지만 팀장에 의해 " + team.getProjectName() + "팀이 해산 되었어요."; - NotificationType notificationType = NotificationType.TEAM_INCOMPLETE; + String body = "아쉽지만 팀장에 의해 " + team.getProjectName() + "팀이 해산 되었어요."; + DeepLinkType deepLinkType = DeepLinkType.TEAM_PAGE; teamMemberRepository.findAllFetchUser(team.getId()) .forEach(teamMember -> - createAndSaveNotification(teamMember.getUser(), notificationType, title, boy) + createAndSaveNotification(teamMember.getUser(), title, body, deepLinkType) ); if (!fcms.isEmpty()) { - Map data = createFcmData(title, boy, notificationType); + Map data = createFcmData(title, body, deepLinkType.getUrl()); MulticastMessage message = createMulticast(fcms, data); sendMulticast(message); @@ -196,13 +197,13 @@ public void sendTeamComplete(Team team) { List fcms = fcmRepository.findAllTeam(team.getId()); String title = team.getProjectName() + " 프로젝트 완료"; String body = "수고하셨어요! 프로젝트를 완료했어요. 팀원 리뷰를 작성해보세요!"; - NotificationType notificationType = NotificationType.TEAM_COMPLETE; + DeepLinkType deepLinkType = DeepLinkType.REVIEW_PAGE; teamMemberRepository.findAllFetchUser(team.getId()) .forEach(teamMember -> - createAndSaveNotification(teamMember.getUser(), notificationType, title, body) + createAndSaveNotification(teamMember.getUser(), title, body, deepLinkType) ); if (!fcms.isEmpty()) { - Map data = createFcmData(title, body, notificationType); + Map data = createFcmData(title, body, deepLinkType.getUrl()); MulticastMessage message = createMulticast(fcms, data); sendMulticast(message); @@ -218,14 +219,14 @@ public void sendTeamProfileUpdated(Team team) { List fcms = fcmRepository.findAllTeam(team.getId()); String title = team.getProjectName() + "팀 프로필 수정"; String body = team.getProjectName() + "팀 프로필이 팀장에 의해 수정되었어요."; - NotificationType notificationType = NotificationType.TEAM_PROFILE_UPDATED; + DeepLinkType deepLinkType = DeepLinkType.TEAM_PAGE; teamMemberRepository.findAllFetchUser(team.getId()) .forEach(teamMember -> - createAndSaveNotification(teamMember.getUser(), notificationType, title, body) + createAndSaveNotification(teamMember.getUser(), title, body, deepLinkType) ); if (!fcms.isEmpty()) { - Map data = createFcmData(title, body, notificationType); + Map data = createFcmData(title, body, deepLinkType.getUrl()); MulticastMessage message = createMulticast(fcms, data); sendMulticast(message); @@ -241,10 +242,10 @@ public void sendOfferByTeam(Offer offer) { List fcms = fcmRepository.findAllUser(offer.getUser().getId()); String title = offer.getPosition().toString() + " 스카웃 제의"; String body = offer.getTeam().getProjectName() + "팀에서 " + offer.getPosition().getText() + " 스카웃 제의가 왔어요!"; - NotificationType notificationType = NotificationType.TEAM_OFFER; - createAndSaveNotification(offer.getUser(), notificationType, title, body); + DeepLinkType deepLinkType = DeepLinkType.USER_OFFER_RECEIVE_PAGE; + createAndSaveNotification(offer.getUser(), title, body, deepLinkType); if (!fcms.isEmpty()) { - Map data = createFcmData(title, body, notificationType); + Map data = createFcmData(title, body, deepLinkType.getUrl()); MulticastMessage message = createMulticast(fcms, data); sendMulticast(message); @@ -260,13 +261,13 @@ public void sendOfferByUser(Offer offer) { Optional teamLeader = teamMemberRepository.findLeaderFetchUser(offer.getTeam().getId()); String title = offer.getPosition().getText() + " 지원"; String body = offer.getPosition().getText() + " " + offer.getUser().getNickname() + "님이 지원을 했습니다."; - NotificationType notificationType = NotificationType.USER_OFFER; + DeepLinkType deepLinkType = DeepLinkType.TEAM_OFFER_RECEIVE_PAGE; if (teamLeader.isPresent()) { - createAndSaveNotification(teamLeader.get().getUser(), notificationType, title, body); + createAndSaveNotification(teamLeader.get().getUser(), title, body, deepLinkType); List fcms = fcmRepository.findAllUser(teamLeader.get().getUser().getId()); if (!fcms.isEmpty()) { - Map data = createFcmData(title, body, notificationType); + Map data = createFcmData(title, body, deepLinkType.getUrl()); MulticastMessage message = createMulticast(fcms, data); sendMulticast(message); @@ -274,12 +275,17 @@ public void sendOfferByUser(Offer offer) { } } - - private Map createFcmData(String title, String body, NotificationType notificationType) { + /** + * FCM 데이터 생성 + * @param title 제목 + * @param body 내용 + * @param deepLinkUrl 딥링크 URL + */ + private Map createFcmData(String title, String body, String deepLinkUrl) { return Map.of( "title", title, "body", body, - "type", notificationType.name(), + "deepLink", deepLinkUrl, "time", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) ); } @@ -324,15 +330,15 @@ public void sendMulticast(MulticastMessage message) { /** * 알림 생성 및 저장 * @param user 회원 - * @param notificationType 알림 종류 * @param title 제목 * @param body 내용 + * @param deepLinkType 딥링크 종류 */ @Transactional - public void createAndSaveNotification(User user, NotificationType notificationType, String title, String body) { + public void createAndSaveNotification(User user, String title, String body, DeepLinkType deepLinkType) { Notification notification = Notification.builder() .user(user) - .notificationType(notificationType) + .deepLinkType(deepLinkType) .title(title) .body(body) .build(); diff --git a/src/main/java/com/gabojait/gabojaitspring/common/constant/deepLink/DeepLink.java b/src/main/java/com/gabojait/gabojaitspring/domain/notification/DeepLinkType.java similarity index 76% rename from src/main/java/com/gabojait/gabojaitspring/common/constant/deepLink/DeepLink.java rename to src/main/java/com/gabojait/gabojaitspring/domain/notification/DeepLinkType.java index ddf8a58d..81a97a2f 100644 --- a/src/main/java/com/gabojait/gabojaitspring/common/constant/deepLink/DeepLink.java +++ b/src/main/java/com/gabojait/gabojaitspring/domain/notification/DeepLinkType.java @@ -1,11 +1,11 @@ -package com.gabojait.gabojaitspring.common.constant.deepLink; +package com.gabojait.gabojaitspring.domain.notification; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; @Getter -@AllArgsConstructor -public enum DeepLink { +@RequiredArgsConstructor +public enum DeepLinkType { HOME_PAGE("gabojait://home", "홈페이지"), TEAM_PAGE("gabojait://team", "팀 페이지"), diff --git a/src/main/java/com/gabojait/gabojaitspring/domain/notification/Notification.java b/src/main/java/com/gabojait/gabojaitspring/domain/notification/Notification.java index b1bc56a7..d3207009 100644 --- a/src/main/java/com/gabojait/gabojaitspring/domain/notification/Notification.java +++ b/src/main/java/com/gabojait/gabojaitspring/domain/notification/Notification.java @@ -23,23 +23,23 @@ public class Notification extends BasePermanentEntity { @JoinColumn(name = "user_id") private User user; - @Column(nullable = false, length = 25) - @Enumerated(EnumType.STRING) - private NotificationType notificationType; @Column(nullable = false) private String title; @Column(nullable = false) private String body; @Column(nullable = false) private Boolean isRead; + @Column(nullable = false, length = 31) + @Enumerated(EnumType.STRING) + private DeepLinkType deepLinkType; @Builder - private Notification(User user, NotificationType notificationType, String title, String body) { + private Notification(User user, String title, String body, DeepLinkType deepLinkType) { this.user = user; - this.notificationType = notificationType; this.title = title; this.body = body; this.isRead = false; + this.deepLinkType = deepLinkType; this.isDeleted = false; } @@ -54,7 +54,7 @@ public boolean equals(Object object) { Notification that = (Notification) object; return Objects.equals(id, that.id) && Objects.equals(user, that.user) - && notificationType == that.notificationType + && deepLinkType == that.deepLinkType && Objects.equals(title, that.title) && Objects.equals(body, that.body) && Objects.equals(isRead, that.isRead); @@ -62,6 +62,6 @@ public boolean equals(Object object) { @Override public int hashCode() { - return Objects.hash(id, user, notificationType, title, body, isRead); + return Objects.hash(id, user, deepLinkType, title, body, isRead); } } diff --git a/src/main/java/com/gabojait/gabojaitspring/domain/notification/NotificationType.java b/src/main/java/com/gabojait/gabojaitspring/domain/notification/NotificationType.java deleted file mode 100644 index cd43615e..00000000 --- a/src/main/java/com/gabojait/gabojaitspring/domain/notification/NotificationType.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gabojait.gabojaitspring.domain.notification; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum NotificationType { - NONE("없음"), - TEAM_PROFILE_UPDATED("팀 프로필 수정"), - USER_OFFER("회원 제안"), - TEAM_OFFER("팀 제안"), - NEW_TEAM_MEMBER("새 팀원"), - FIRED_TEAM_MEMBER("팀원 추방"), - QUIT_TEAM_MEMBER("팀원 포기"), - TEAM_INCOMPLETE("프로젝트 미완료"), - TEAM_COMPLETE("프로젝트 완료"); - - private final String text; -} diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 9ce57772..c4849f65 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -126,7 +126,7 @@ CREATE TABLE notification notification_id BIGINT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, body VARCHAR(255) NOT NULL, - notification_type VARCHAR(25) NOT NULL, + deep_link_type VARCHAR(31) NOT NULL, is_read BIT NOT NULL, created_at DATETIME(6) NOT NULL, updated_at DATETIME(6) NOT NULL, diff --git a/src/test/java/com/gabojait/gabojaitspring/api/service/notification/NotificationServiceTest.java b/src/test/java/com/gabojait/gabojaitspring/api/service/notification/NotificationServiceTest.java index 2b8506b4..7ac17dd1 100644 --- a/src/test/java/com/gabojait/gabojaitspring/api/service/notification/NotificationServiceTest.java +++ b/src/test/java/com/gabojait/gabojaitspring/api/service/notification/NotificationServiceTest.java @@ -2,8 +2,8 @@ import com.gabojait.gabojaitspring.api.dto.notification.response.NotificationPageResponse; import com.gabojait.gabojaitspring.common.response.PageData; +import com.gabojait.gabojaitspring.domain.notification.DeepLinkType; import com.gabojait.gabojaitspring.domain.notification.Notification; -import com.gabojait.gabojaitspring.domain.notification.NotificationType; import com.gabojait.gabojaitspring.domain.offer.Offer; import com.gabojait.gabojaitspring.domain.offer.OfferedBy; import com.gabojait.gabojaitspring.domain.team.Team; @@ -55,9 +55,9 @@ void givenValid_whenFindPageNotifications_thenReturn() { // given User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); - Notification notification1 = createSavedNotification(user, NotificationType.NONE, "알림 제목1", "알림1이 왔습니다."); - Notification notification2 = createSavedNotification(user, NotificationType.TEAM_OFFER, "알림 제목2", "알림1이 왔습니다."); - Notification notification3 = createSavedNotification(user, NotificationType.USER_OFFER, "알림 제목3", "알림1이 왔습니다."); + Notification notification1 = createSavedNotification(user, "알림 제목1", "알림1이 왔습니다.", DeepLinkType.HOME_PAGE); + Notification notification2 = createSavedNotification(user, "알림 제목2", "알림2이 왔습니다.", DeepLinkType.HOME_PAGE); + Notification notification3 = createSavedNotification(user, "알림 제목3", "알림3이 왔습니다.", DeepLinkType.HOME_PAGE); long pageFrom = Long.MAX_VALUE; int pageSize = 2; @@ -69,16 +69,23 @@ void givenValid_whenFindPageNotifications_thenReturn() { // then assertAll( () -> assertThat(responses.getData()) - .extracting("notificationId", "notificationType", "title", "body", "isRead", "createdAt", "updatedAt") + .extracting("notificationId", "title", "body", "isRead", "createdAt", "updatedAt") .containsExactly( - tuple(notification3.getId(), notification3.getNotificationType(), notification3.getTitle(), - notification3.getBody(), notification3.getIsRead(), notification3.getCreatedAt(), + tuple(notification3.getId(), notification3.getTitle(), notification3.getBody(), + notification3.getIsRead(), notification3.getCreatedAt(), notification3.getUpdatedAt()), - tuple(notification2.getId(), notification2.getNotificationType(), notification2.getTitle(), - notification2.getBody(), notification2.getIsRead(), notification2.getCreatedAt(), + tuple(notification2.getId(), notification2.getTitle(), notification2.getBody(), + notification2.getIsRead(), notification2.getCreatedAt(), notification2.getUpdatedAt()) ), - () -> assertThat(responses.getData().size()).isEqualTo(pageSize), + () -> assertThat(responses.getData()) + .extracting("deepLink").extracting("url", "description") + .containsExactly( + tuple(notification3.getDeepLinkType().getUrl(), + notification3.getDeepLinkType().getDescription()), + tuple(notification2.getDeepLinkType().getUrl(), + notification2.getDeepLinkType().getDescription()) + ), () -> assertThat(responses.getTotal()).isEqualTo(3) ); } @@ -89,14 +96,13 @@ void giveValid_whenReadNotification_thenReturn() { // given User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); - Notification notification = createSavedNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); + Notification notification = createSavedNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE); // when notificationService.readNotification(user.getId(), notification.getId()); // then - Optional foundNotification = notificationRepository.findUnread(user.getId(), - notification.getId()); + Optional foundNotification = notificationRepository.findUnread(user.getId(), notification.getId()); assertThat(foundNotification).isEmpty(); } @@ -107,7 +113,7 @@ void giveRead_whenReadNotification_thenReturn() { // given User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); - Notification notification = createSavedNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); + Notification notification = createSavedNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE); notification.read(); notificationRepository.save(notification); @@ -144,24 +150,25 @@ void givenValid_whenSendTeamMemberJoin_thenReturn() { assertAll( () -> assertThat(notifications1) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.NEW_TEAM_MEMBER, "새로운 " + offer.getPosition().getText() + " 합류", - user3.getNickname() + "님이 " + offer.getPosition().getText() + "로 팀에 합류하였어요.", false, - false) + tuple("새로운 " + offer.getPosition().getText() + " 합류", + user3.getNickname() + "님이 " + offer.getPosition().getText() + "로 팀에 합류하였어요.", + false, DeepLinkType.TEAM_PAGE, false, user1) ), () -> assertThat(notifications2) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.NEW_TEAM_MEMBER, "새로운 " + offer.getPosition().getText() + " 합류", - user3.getNickname() + "님이 " + offer.getPosition().getText() + "로 팀에 합류하였어요.", false, - false) + tuple("새로운 " + offer.getPosition().getText() + " 합류", + user3.getNickname() + "님이 " + offer.getPosition().getText() + "로 팀에 합류하였어요.", + false, DeepLinkType.TEAM_PAGE, false, user2) ), () -> assertThat(notifications3) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.NEW_TEAM_MEMBER, team.getProjectName() + "팀 합류", - offer.getPosition().getText() + "로서 역량을 펼쳐보세요!", false, false) + tuple(team.getProjectName() + "팀 합류", + offer.getPosition().getText() + "로서 역량을 펼쳐보세요!", + false, DeepLinkType.TEAM_PAGE, false, user3) ) ); } @@ -189,22 +196,25 @@ void givenValid_whenSendTeamMemberFired_thenReturn() { assertAll( () -> assertThat(notifications1) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.FIRED_TEAM_MEMBER, user3.getNickname() + "님 팀에서 추방", - user3.getNickname() + "님이 팀장에 의해 추방되었어요.", false, false) + tuple(user3.getNickname() + "님 팀에서 추방", + user3.getNickname() + "님이 팀장에 의해 추방되었어요.", false, DeepLinkType.TEAM_PAGE, + false, user1) ), () -> assertThat(notifications2) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.FIRED_TEAM_MEMBER, user3.getNickname() + "님 팀에서 추방", - user3.getNickname() + "님이 팀장에 의해 추방되었어요.", false, false) + tuple(user3.getNickname() + "님 팀에서 추방", + user3.getNickname() + "님이 팀장에 의해 추방되었어요.", false, DeepLinkType.TEAM_PAGE, + false, user2) ), () -> assertThat(notifications3) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.FIRED_TEAM_MEMBER, team.getProjectName() + "팀에서 추방", - team.getProjectName() + "팀에서 추방 되었어요. 아쉽지만 새로운 팀을 찾아보세요.", false, false) + tuple(team.getProjectName() + "팀에서 추방", + team.getProjectName() + "팀에서 추방 되었어요. 아쉽지만 새로운 팀을 찾아보세요.", false, + DeepLinkType.HOME_PAGE, false, user3) ) ); } @@ -232,16 +242,16 @@ void givenValid_whenSendTeamMemberQuit_thenReturn() { assertAll( () -> assertThat(notifications1) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.QUIT_TEAM_MEMBER, user3.getNickname() + "님 팀 탈퇴", - user3.getNickname() + "님이 팀에서 탈퇴하였습니다.", false, false) + tuple(user3.getNickname() + "님 팀 탈퇴", user3.getNickname() + "님이 팀에서 탈퇴하였습니다.", + false, DeepLinkType.TEAM_PAGE, false, user1) ), () -> assertThat(notifications2) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.QUIT_TEAM_MEMBER, user3.getNickname() + "님 팀 탈퇴", - user3.getNickname() + "님이 팀에서 탈퇴하였습니다.", false, false) + tuple(user3.getNickname() + "님 팀 탈퇴", user3.getNickname() + "님이 팀에서 탈퇴하였습니다.", + false, DeepLinkType.TEAM_PAGE, false, user2) ), () -> assertThat(notifications3).isEmpty() ); @@ -270,22 +280,25 @@ void givenValid_whenSendTeamIncomplete_thenReturn() { assertAll( () -> assertThat(notifications1) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_INCOMPLETE, team.getProjectName() + "팀 해산", - "아쉽지만 팀장에 의해 " + team.getProjectName() + "팀이 해산 되었어요.", false, false) + tuple(team.getProjectName() + "팀 해산", + "아쉽지만 팀장에 의해 " + team.getProjectName() + "팀이 해산 되었어요.", false, + DeepLinkType.TEAM_PAGE, false, user1) ), () -> assertThat(notifications2) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_INCOMPLETE, team.getProjectName() + "팀 해산", - "아쉽지만 팀장에 의해 " + team.getProjectName() + "팀이 해산 되었어요.", false, false) + tuple(team.getProjectName() + "팀 해산", + "아쉽지만 팀장에 의해 " + team.getProjectName() + "팀이 해산 되었어요.", false, + DeepLinkType.TEAM_PAGE, false, user2) ), () -> assertThat(notifications3) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_INCOMPLETE, team.getProjectName() + "팀 해산", - "아쉽지만 팀장에 의해 " + team.getProjectName() + "팀이 해산 되었어요.", false, false) + tuple(team.getProjectName() + "팀 해산", + "아쉽지만 팀장에 의해 " + team.getProjectName() + "팀이 해산 되었어요.", false, + DeepLinkType.TEAM_PAGE, false, user3) ) ); } @@ -313,22 +326,25 @@ void givenValid_whenSendTeamComplete_thenReturn() { assertAll( () -> assertThat(notifications1) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_COMPLETE, team.getProjectName() + " 프로젝트 완료", - "수고하셨어요! 프로젝트를 완료했어요. 팀원 리뷰를 작성해보세요!", false, false) + tuple(team.getProjectName() + " 프로젝트 완료", + "수고하셨어요! 프로젝트를 완료했어요. 팀원 리뷰를 작성해보세요!", false, + DeepLinkType.REVIEW_PAGE, false, user1) ), () -> assertThat(notifications2) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_COMPLETE, team.getProjectName() + " 프로젝트 완료", - "수고하셨어요! 프로젝트를 완료했어요. 팀원 리뷰를 작성해보세요!", false, false) + tuple(team.getProjectName() + " 프로젝트 완료", + "수고하셨어요! 프로젝트를 완료했어요. 팀원 리뷰를 작성해보세요!", false, + DeepLinkType.REVIEW_PAGE, false, user2) ), () -> assertThat(notifications3) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_COMPLETE, team.getProjectName() + " 프로젝트 완료", - "수고하셨어요! 프로젝트를 완료했어요. 팀원 리뷰를 작성해보세요!", false, false) + tuple(team.getProjectName() + " 프로젝트 완료", + "수고하셨어요! 프로젝트를 완료했어요. 팀원 리뷰를 작성해보세요!", false, + DeepLinkType.REVIEW_PAGE, false, user3) ) ); } @@ -356,22 +372,25 @@ void givenValid_whenSendTeamProfileUpdated_thenReturn() { assertAll( () -> assertThat(notifications1) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_PROFILE_UPDATED, team.getProjectName() + "팀 프로필 수정", - team.getProjectName() + "팀 프로필이 팀장에 의해 수정되었어요.", false, false) + tuple(team.getProjectName() + "팀 프로필 수정", + team.getProjectName() + "팀 프로필이 팀장에 의해 수정되었어요.", false, + DeepLinkType.TEAM_PAGE, false, user1) ), () -> assertThat(notifications2) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_PROFILE_UPDATED, team.getProjectName() + "팀 프로필 수정", - team.getProjectName() + "팀 프로필이 팀장에 의해 수정되었어요.", false, false) + tuple(team.getProjectName() + "팀 프로필 수정", + team.getProjectName() + "팀 프로필이 팀장에 의해 수정되었어요.", false, + DeepLinkType.TEAM_PAGE, false, user2) ), () -> assertThat(notifications3) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_PROFILE_UPDATED, team.getProjectName() + "팀 프로필 수정", - team.getProjectName() + "팀 프로필이 팀장에 의해 수정되었어요.", false, false) + tuple(team.getProjectName() + "팀 프로필 수정", + team.getProjectName() + "팀 프로필이 팀장에 의해 수정되었어요.", false, + DeepLinkType.TEAM_PAGE, false, user3) ) ); } @@ -400,11 +419,11 @@ void givenValid_whenSendOfferByTeam_thenReturn() { assertAll( () -> assertThat(notifications3) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.TEAM_OFFER, offer.getPosition().toString() + " 스카웃 제의", + tuple(offer.getPosition().toString() + " 스카웃 제의", offer.getTeam().getProjectName() + "팀에서 " + offer.getPosition().getText() + " 스카웃 제의가 왔어요!", - false, false) + false, DeepLinkType.USER_OFFER_RECEIVE_PAGE, false, user3) ), () -> assertThat(notifications1).isEmpty(), () -> assertThat(notifications2).isEmpty() @@ -435,23 +454,23 @@ void givenValid_whenSendOfferByUser_thenReturn() { assertAll( () -> assertThat(notifications1) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") .containsExactlyInAnyOrder( - tuple(NotificationType.USER_OFFER, offer.getPosition().getText() + " 지원", + tuple(offer.getPosition().getText() + " 지원", offer.getPosition().getText() + " " + offer.getUser().getNickname() + "님이 지원을 했습니다.", - false, false) + false, DeepLinkType.TEAM_OFFER_RECEIVE_PAGE, false, user1) ), () -> assertThat(notifications2).isEmpty(), () -> assertThat(notifications3).isEmpty() ); } - private Notification createSavedNotification(User user, NotificationType notificationType, String title, String body) { + private Notification createSavedNotification(User user, String title, String body, DeepLinkType deepLinkType) { Notification notification = Notification.builder() .user(user) - .notificationType(notificationType) .title(title) .body(body) + .deepLinkType(deepLinkType) .build(); return notificationRepository.save(notification); diff --git a/src/test/java/com/gabojait/gabojaitspring/domain/notification/DeepLinkTypeTest.java b/src/test/java/com/gabojait/gabojaitspring/domain/notification/DeepLinkTypeTest.java new file mode 100644 index 00000000..ac5b2953 --- /dev/null +++ b/src/test/java/com/gabojait/gabojaitspring/domain/notification/DeepLinkTypeTest.java @@ -0,0 +1,65 @@ +package com.gabojait.gabojaitspring.domain.notification; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +class DeepLinkTypeTest { + + private static Stream providerGetUrlAndDescription() { + return Stream.of( + Arguments.of(DeepLinkType.HOME_PAGE, "gabojait://home", "홈페이지"), + Arguments.of(DeepLinkType.TEAM_PAGE, "gabojait://team", "팀 페이지"), + Arguments.of(DeepLinkType.REVIEW_PAGE, "gabojait://my/team-history/review", "리뷰 작성 페이지"), + Arguments.of(DeepLinkType.USER_OFFER_RECEIVE_PAGE, "gabojait://my/offer/user/received", "회원 제안 페이지"), + Arguments.of(DeepLinkType.TEAM_OFFER_RECEIVE_PAGE, "gabojait://my/offer/team/received", "팀 제안 페이지") + ); + } + + @ParameterizedTest(name = "[{index}] {0} 딥링크 URL은 {1}이고 설명은 {2}다") + @MethodSource("providerGetUrlAndDescription") + @DisplayName("딥링크 타입을 반환한다") + void givenProvider_whenGetUrlAndDescription_thenReturn(DeepLinkType deepLinkType, String url, String description) { + // when & then + assertThat(deepLinkType) + .extracting("url", "description") + .isEqualTo(List.of(url, description)); + } + + @Test + @DisplayName("전체 딥링크 타입 반환이 정상 작동한다") + void givenValid_whenValues_thenReturn() { + // given & when + DeepLinkType[] deepLinkTypes = DeepLinkType.values(); + + // then + assertThat(deepLinkTypes) + .containsExactly(DeepLinkType.HOME_PAGE, DeepLinkType.TEAM_PAGE, DeepLinkType.REVIEW_PAGE, + DeepLinkType.USER_OFFER_RECEIVE_PAGE, DeepLinkType.TEAM_OFFER_RECEIVE_PAGE); + } + + private static Stream providerValueOf() { + return Stream.of( + Arguments.of("HOME_PAGE", DeepLinkType.HOME_PAGE), + Arguments.of("TEAM_PAGE", DeepLinkType.TEAM_PAGE), + Arguments.of("REVIEW_PAGE", DeepLinkType.REVIEW_PAGE), + Arguments.of("USER_OFFER_RECEIVE_PAGE", DeepLinkType.USER_OFFER_RECEIVE_PAGE), + Arguments.of("TEAM_OFFER_RECEIVE_PAGE", DeepLinkType.TEAM_OFFER_RECEIVE_PAGE) + ); + } + + @ParameterizedTest(name = "[{index}] {0} 값을 {1} 딥링크 타입으로 변환한다") + @MethodSource("providerValueOf") + @DisplayName("딥링크 타입 값을 변환한다") + void givenProvider_whenValueOf_thenReturn(String value, DeepLinkType deepLinkType) { + // when & then + assertThat(DeepLinkType.valueOf(value)).isEqualTo(deepLinkType); + } +} \ No newline at end of file diff --git a/src/test/java/com/gabojait/gabojaitspring/domain/notification/NotificationTest.java b/src/test/java/com/gabojait/gabojaitspring/domain/notification/NotificationTest.java index 52237515..e969b752 100644 --- a/src/test/java/com/gabojait/gabojaitspring/domain/notification/NotificationTest.java +++ b/src/test/java/com/gabojait/gabojaitspring/domain/notification/NotificationTest.java @@ -14,7 +14,7 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertTrue; class NotificationTest { @@ -24,17 +24,16 @@ void builder() { // given User user = createDefaultUser("tester@gabojait.com", "tester", "테스터", LocalDate.of(1997, 2, 11), LocalDateTime.now()); - NotificationType notificationType = NotificationType.NONE; String title = "알림 제목"; String body = "알림이 왔습니다."; // when - Notification notification = createNotification(user, notificationType, title, body); + Notification notification = createNotification(user, title, body, DeepLinkType.HOME_PAGE); // then assertThat(notification) - .extracting("notificationType", "title", "body", "isRead", "isDeleted") - .containsExactly(notificationType, title, body, false, false); + .extracting("title", "body", "isRead", "deepLinkType", "isDeleted", "user") + .containsExactly(title, body, false, DeepLinkType.HOME_PAGE, false, user); } @Test @@ -43,7 +42,7 @@ void read() { // given User user = createDefaultUser("tester@gabojait.com", "tester", "테스터", LocalDate.of(1997, 2, 11), LocalDateTime.now()); - Notification notification = createNotification(user, NotificationType.TEAM_OFFER, "알림 제목", "알림이 왔습니다."); + Notification notification = createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE); // when notification.read(); @@ -55,40 +54,40 @@ void read() { private static Stream providerEquals() { User user = createDefaultUser("tester@gabojait.com", "tester", "테스터", LocalDate.of(1997, 2, 11), LocalDateTime.now()); - Notification notification = createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); + Notification notification = createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE); User user1 = createDefaultUser("tester1@gabojait.com", "tester1", "테스터일", LocalDate.of(1997, 2, 11), LocalDateTime.now()); - Notification userNotification1 = createNotification(user1, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); + Notification userNotification1 = createNotification(user1, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE); User user2 = createDefaultUser("tester2@gabojait.com", "tester2", "테스터이", LocalDate.of(1997, 2, 11), LocalDateTime.now()); - Notification userNotification2 = createNotification(user2, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); + Notification userNotification2 = createNotification(user2, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE); - Notification isReadNotification1 = createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); - Notification isReadNotification2 = createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); + Notification isReadNotification1 = createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE); + Notification isReadNotification2 = createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE); isReadNotification2.read(); return Stream.of( Arguments.of(notification, notification, true), Arguments.of(notification, new Object(), false), Arguments.of( - createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."), - createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."), + createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), + createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), true ), Arguments.of( - createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."), - createNotification(user, NotificationType.USER_OFFER, "알림 제목", "알림이 왔습니다."), + createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), + createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.TEAM_PAGE), false ), Arguments.of( - createNotification(user, NotificationType.NONE, "알림 제목1", "알림이 왔습니다."), - createNotification(user, NotificationType.NONE, "알림 제목2", "알림이 왔습니다."), + createNotification(user, "알림 제목1", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), + createNotification(user, "알림 제목2", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), false ), Arguments.of( - createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다.1"), - createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다.2"), + createNotification(user, "알림 제목", "알림이 왔습니다.1", DeepLinkType.HOME_PAGE), + createNotification(user, "알림 제목", "알림이 왔습니다.2", DeepLinkType.HOME_PAGE), false ), Arguments.of(userNotification1, userNotification2, false), @@ -110,13 +109,13 @@ private static Stream providerHashCode() { return Stream.of( Arguments.of( - createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."), - createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."), + createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), + createNotification(user, "알림 제목", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), true ), Arguments.of( - createNotification(user, NotificationType.NONE, "알림 제목1", "알림이 왔습니다."), - createNotification(user, NotificationType.NONE, "알림 제목2", "알림이 왔습니다."), + createNotification(user, "알림 제목1", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), + createNotification(user, "알림 제목2", "알림이 왔습니다.", DeepLinkType.HOME_PAGE), false ) ); @@ -134,12 +133,12 @@ void givenProvider_whenHashCode_thenReturn(Notification notification1, Notificat assertThat(hashCode1 == hashCode2).isEqualTo(result); } - private static Notification createNotification(User user, NotificationType notificationType, String title, String body) { + private static Notification createNotification(User user, String title, String body, DeepLinkType deepLinkType) { return Notification.builder() .user(user) - .notificationType(notificationType) .title(title) .body(body) + .deepLinkType(deepLinkType) .build(); } diff --git a/src/test/java/com/gabojait/gabojaitspring/domain/notification/NotificationTypeTest.java b/src/test/java/com/gabojait/gabojaitspring/domain/notification/NotificationTypeTest.java deleted file mode 100644 index abe11721..00000000 --- a/src/test/java/com/gabojait/gabojaitspring/domain/notification/NotificationTypeTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.gabojait.gabojaitspring.domain.notification; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; - -class NotificationTypeTest { - - private static Stream providerGetText() { - return Stream.of( - Arguments.of(NotificationType.NONE, "없음"), - Arguments.of(NotificationType.TEAM_PROFILE_UPDATED, "팀 프로필 수정"), - Arguments.of(NotificationType.USER_OFFER, "회원 제안"), - Arguments.of(NotificationType.TEAM_OFFER, "팀 제안"), - Arguments.of(NotificationType.NEW_TEAM_MEMBER, "새 팀원"), - Arguments.of(NotificationType.FIRED_TEAM_MEMBER, "팀원 추방"), - Arguments.of(NotificationType.QUIT_TEAM_MEMBER, "팀원 포기"), - Arguments.of(NotificationType.TEAM_INCOMPLETE, "프로젝트 미완료"), - Arguments.of(NotificationType.TEAM_COMPLETE, "프로젝트 완료") - ); - } - - @ParameterizedTest(name = "[{index}] {0} 알림 타입은 {1}다") - @MethodSource("providerGetText") - @DisplayName("알림 타입을 반환한다") - void givenProvider_whenGetText_thenReturn(NotificationType notificationType, String text) { - // when & then - assertThat(notificationType.getText()).isEqualTo(text); - } - - @Test - @DisplayName("전체 알림 타입 반환이 정상 작동한다") - void values() { - // given & when - NotificationType[] notificationTypes = NotificationType.values(); - - // then - assertThat(notificationTypes).containsExactlyInAnyOrder(NotificationType.NONE, - NotificationType.TEAM_PROFILE_UPDATED, NotificationType.USER_OFFER, NotificationType.TEAM_OFFER, - NotificationType.NEW_TEAM_MEMBER, NotificationType.FIRED_TEAM_MEMBER, NotificationType.QUIT_TEAM_MEMBER, - NotificationType.TEAM_INCOMPLETE, NotificationType.TEAM_COMPLETE); - } - - private static Stream providerValueOf() { - return Stream.of( - Arguments.of("NONE", NotificationType.NONE), - Arguments.of("TEAM_PROFILE_UPDATED", NotificationType.TEAM_PROFILE_UPDATED), - Arguments.of("USER_OFFER", NotificationType.USER_OFFER), - Arguments.of("TEAM_OFFER", NotificationType.TEAM_OFFER), - Arguments.of("NEW_TEAM_MEMBER", NotificationType.NEW_TEAM_MEMBER), - Arguments.of("FIRED_TEAM_MEMBER", NotificationType.FIRED_TEAM_MEMBER), - Arguments.of("QUIT_TEAM_MEMBER", NotificationType.QUIT_TEAM_MEMBER), - Arguments.of("TEAM_INCOMPLETE", NotificationType.TEAM_INCOMPLETE), - Arguments.of("TEAM_COMPLETE", NotificationType.TEAM_COMPLETE) - ); - } - - @ParameterizedTest(name = "[{index}] {0} 값을 {1} 알림 타입으로 변환한다") - @MethodSource("providerValueOf") - @DisplayName("알림 타입 값을 변환한다") - void givenProvider_whenValueOf_thenReturn(String value, NotificationType notificationType) { - // when & then - assertThat(NotificationType.valueOf(value)).isEqualTo(notificationType); - } -} \ No newline at end of file diff --git a/src/test/java/com/gabojait/gabojaitspring/repository/notification/NotificationRepositoryTest.java b/src/test/java/com/gabojait/gabojaitspring/repository/notification/NotificationRepositoryTest.java index 2251050a..210f170a 100644 --- a/src/test/java/com/gabojait/gabojaitspring/repository/notification/NotificationRepositoryTest.java +++ b/src/test/java/com/gabojait/gabojaitspring/repository/notification/NotificationRepositoryTest.java @@ -1,8 +1,8 @@ package com.gabojait.gabojaitspring.repository.notification; import com.gabojait.gabojaitspring.common.response.PageData; +import com.gabojait.gabojaitspring.domain.notification.DeepLinkType; import com.gabojait.gabojaitspring.domain.notification.Notification; -import com.gabojait.gabojaitspring.domain.notification.NotificationType; import com.gabojait.gabojaitspring.domain.user.Contact; import com.gabojait.gabojaitspring.domain.user.Gender; import com.gabojait.gabojaitspring.domain.user.User; @@ -36,11 +36,11 @@ class NotificationRepositoryTest { @DisplayName("알림이 있을시 알림 페이징 조회가 정상 작동한다") void givenValid_whenFindPage_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); + User user = createSavedDefaultUser(); - Notification notification1 = createNotification(user, NotificationType.NONE, "알림 제목1", "알림1이 왔습니다."); - Notification notification2 = createNotification(user, NotificationType.USER_OFFER, "알림 제목2", "알림2이 왔습니다."); - Notification notification3 = createNotification(user, NotificationType.TEAM_OFFER, "알림 제목3", "알림3이 왔습니다."); + Notification notification1 = createNotification(user, "알림 제목1", "알림1이 왔습니다."); + Notification notification2 = createNotification(user, "알림 제목2", "알림2이 왔습니다."); + Notification notification3 = createNotification(user, "알림 제목3", "알림3이 왔습니다."); notificationRepository.saveAll(List.of(notification1, notification2, notification3)); long pageFrom = notification3.getId(); @@ -61,7 +61,7 @@ void givenValid_whenFindPage_thenReturn() { @DisplayName("알림이 없을시 알림 페이징 조회가 정상 작동한다") void givenNoneExisting_whenFindPage_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); + User user = createSavedDefaultUser(); long pageFrom = Long.MAX_VALUE; int pageSize = 1; @@ -80,9 +80,9 @@ void givenNoneExisting_whenFindPage_thenReturn() { @DisplayName("읽지 않은 알림을 조회가 정상 작동한다") void givenRead_whenFindUnread_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); + User user = createSavedDefaultUser(); - Notification notification = createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); + Notification notification = createNotification(user, "알림 제목", "알림이 왔습니다."); notificationRepository.save(notification); // when @@ -96,9 +96,9 @@ void givenRead_whenFindUnread_thenReturn() { @DisplayName("알림은 읽은 후 읽은 알림을 조회가 정상 작동한다") void givenUnread_whenFindUnread_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); + User user = createSavedDefaultUser(); - Notification notification = createNotification(user, NotificationType.NONE, "알림 제목", "알림이 왔습니다."); + Notification notification = createNotification(user, "알림 제목", "알림이 왔습니다."); notification.read(); notificationRepository.save(notification); @@ -109,27 +109,27 @@ void givenUnread_whenFindUnread_thenReturn() { assertThat(foundNotification).isEmpty(); } - private Notification createNotification(User user, NotificationType notificationType, String title, String body) { + private Notification createNotification(User user, String title, String body) { return Notification.builder() .user(user) - .notificationType(notificationType) .title(title) .body(body) + .deepLinkType(DeepLinkType.HOME_PAGE) .build(); } - private User createSavedDefaultUser(String email, String username, String nickname) { + private User createSavedDefaultUser() { Contact contact = Contact.builder() - .email(email) + .email("tester@gabojait.com") .verificationCode("000000") .build(); contact.verified(); contactRepository.save(contact); User user = User.builder() - .username(username) + .username("tester") .password("password1!") - .nickname(nickname) + .nickname("테스터") .gender(Gender.M) .birthdate(LocalDate.of(1997, 2, 11)) .lastRequestAt(LocalDateTime.now())