diff --git a/src/test/java/codesquad/fineants/spring/api/member/controller/MemberNotificationRestControllerTest.java b/src/test/java/codesquad/fineants/spring/api/member/controller/MemberNotificationRestControllerTest.java index d759dfd68..a8498700d 100644 --- a/src/test/java/codesquad/fineants/spring/api/member/controller/MemberNotificationRestControllerTest.java +++ b/src/test/java/codesquad/fineants/spring/api/member/controller/MemberNotificationRestControllerTest.java @@ -30,6 +30,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import codesquad.fineants.domain.member.Member; +import codesquad.fineants.domain.notification.NotificationBody; import codesquad.fineants.domain.oauth.support.AuthMember; import codesquad.fineants.domain.oauth.support.AuthPrincipalArgumentResolver; import codesquad.fineants.spring.api.errors.handler.GlobalExceptionHandler; @@ -190,7 +191,10 @@ void readNotification() throws Exception { MemberNotification mockNotification = MemberNotification.builder() .notificationId(3L) .title("포트폴리오") - .body("포트폴리오2의 최대 손실율을 초과했습니다") + .body(NotificationBody.builder() + .name("포트폴리오2") + .target("최대 손실율") + .build()) .timestamp(LocalDateTime.of(2024, 1, 24, 10, 10, 10)) .isRead(false) .type("portfolio") @@ -242,7 +246,10 @@ void deleteNotification() throws Exception { MemberNotification mockNotification = MemberNotification.builder() .notificationId(3L) .title("포트폴리오") - .body("포트폴리오2의 최대 손실율을 초과했습니다") + .body(NotificationBody.builder() + .name("포트폴리오2") + .target("최대 손실율") + .build()) .timestamp(LocalDateTime.of(2024, 1, 24, 10, 10, 10)) .isRead(false) .type("portfolio") @@ -268,7 +275,8 @@ void sendNotification() throws Exception { Member member = createMember(); MemberNotificationSendRequest request = MemberNotificationSendRequest.builder() .title("포트폴리오") - .body("포트폴리오1의 최대 손실율을 초과했습니다") + .name("포트폴리오1") + .target("최대 손실율") .type("portfolio") .referenceId("1") .build(); @@ -310,7 +318,10 @@ private List createNotifications() { return List.of(MemberNotification.builder() .notificationId(3L) .title("포트폴리오") - .body("포트폴리오2의 최대 손실율을 초과했습니다") + .body(NotificationBody.builder() + .name("포트폴리오2") + .target("최대 손실율") + .build()) .timestamp(LocalDateTime.of(2024, 1, 24, 10, 10, 10)) .isRead(false) .type("portfolio") @@ -319,7 +330,10 @@ private List createNotifications() { MemberNotification.builder() .notificationId(2L) .title("포트폴리오") - .body("포트폴리오1의 목표 수익률을 달성했습니다") + .body(NotificationBody.builder() + .name("포트폴리오1") + .target("목표 수익률") + .build()) .timestamp(LocalDateTime.of(2024, 1, 23, 10, 10, 10)) .isRead(false) .type("portfolio") @@ -328,7 +342,10 @@ private List createNotifications() { MemberNotification.builder() .notificationId(1L) .title("지정가") - .body("삼성전자가 지정가 KRW60000에 도달했습니다") + .body(NotificationBody.builder() + .name("삼성전자") + .target("65000") + .build()) .timestamp(LocalDateTime.of(2024, 1, 22, 10, 10, 10)) .isRead(true) .type("stock") diff --git a/src/test/java/codesquad/fineants/spring/api/member/service/MemberNotificationServiceTest.java b/src/test/java/codesquad/fineants/spring/api/member/service/MemberNotificationServiceTest.java index f6b742217..b4bd243e5 100644 --- a/src/test/java/codesquad/fineants/spring/api/member/service/MemberNotificationServiceTest.java +++ b/src/test/java/codesquad/fineants/spring/api/member/service/MemberNotificationServiceTest.java @@ -18,7 +18,11 @@ import codesquad.fineants.domain.member.Member; import codesquad.fineants.domain.member.MemberRepository; import codesquad.fineants.domain.notification.Notification; +import codesquad.fineants.domain.notification.NotificationBody; import codesquad.fineants.domain.notification.NotificationRepository; +import codesquad.fineants.domain.notification.PortfolioNotification; +import codesquad.fineants.domain.notification.PortfolioNotificationType; +import codesquad.fineants.domain.notification.StockTargetPriceNotification; import codesquad.fineants.spring.AbstractContainerBaseTest; import codesquad.fineants.spring.api.errors.errorcode.NotificationErrorCode; import codesquad.fineants.spring.api.errors.exception.NotFoundResourceException; @@ -67,7 +71,10 @@ void fetchNotifications() { MemberNotification.builder() .notificationId(notifications.get(2).getId()) .title("포트폴리오") - .body("포트폴리오2의 최대 손실율을 초과했습니다") + .body(NotificationBody.builder() + .name("포트폴리오2") + .target("최대 손실율") + .build()) .timestamp(LocalDateTime.of(2024, 1, 24, 10, 10, 10)) .isRead(false) .type("portfolio") @@ -76,7 +83,10 @@ void fetchNotifications() { MemberNotification.builder() .notificationId(notifications.get(1).getId()) .title("포트폴리오") - .body("포트폴리오1의 목표 수익률을 달성했습니다") + .body(NotificationBody.builder() + .name("포트폴리오1") + .target("목표 수익률") + .build()) .timestamp(LocalDateTime.of(2024, 1, 23, 10, 10, 10)) .isRead(false) .type("portfolio") @@ -85,7 +95,10 @@ void fetchNotifications() { MemberNotification.builder() .notificationId(notifications.get(0).getId()) .title("지정가") - .body("삼성전자가 지정가 KRW60000에 도달했습니다") + .body(NotificationBody.builder() + .name("삼성전자") + .target("65000") + .build()) .timestamp(LocalDateTime.of(2024, 1, 22, 10, 10, 10)) .isRead(true) .type("stock") @@ -191,7 +204,8 @@ void sendNotification() { fcmRepository.save(createFcmToken(member)); MemberNotificationSendRequest request = MemberNotificationSendRequest.builder() .title("포트폴리오") - .body("포트폴리오1의 최대 손실율을 초과했습니다") + .name("포트폴리오1") + .target("최대 손실율") .type("portfolio") .referenceId("1") .build(); @@ -203,7 +217,7 @@ void sendNotification() { assertAll( () -> assertThat(response) .extracting("title", "content", "isRead", "type", "referenceId") - .containsExactly("포트폴리오", "포트폴리오1의 최대 손실율을 초과했습니다", false, "portfolio", "1"), + .containsExactly("포트폴리오", "포트폴리오1이(가) 최대 손실율에 도달했습니다", false, "portfolio", "1"), () -> assertThat(response) .extracting("sendMessageIds") .asList() @@ -220,7 +234,8 @@ void sendNotification_whenInvalidTokenOfTokens_thenDeleteInvalidToken() { FcmToken saveFcmToken = fcmRepository.save(createFcmToken(member, "fcmToken")); MemberNotificationSendRequest request = MemberNotificationSendRequest.builder() .title("포트폴리오") - .body("포트폴리오1의 최대 손실율을 초과했습니다") + .name("포트폴리오1") + .target("최대 손실율") .type("portfolio") .referenceId("1") .build(); @@ -232,7 +247,7 @@ void sendNotification_whenInvalidTokenOfTokens_thenDeleteInvalidToken() { assertAll( () -> assertThat(response) .extracting("title", "content", "isRead", "type", "referenceId") - .containsExactly("포트폴리오", "포트폴리오1의 최대 손실율을 초과했습니다", false, "portfolio", "1"), + .containsExactly("포트폴리오", "포트폴리오1이(가) 최대 손실율에 도달했습니다", false, "portfolio", "1"), () -> assertThat(response) .extracting("sendMessageIds") .asList() @@ -248,7 +263,8 @@ void sendNotification_whenEmptyToken_thenDoNotSendNotification() { Member member = memberRepository.save(createMember()); MemberNotificationSendRequest request = MemberNotificationSendRequest.builder() .title("포트폴리오") - .body("포트폴리오1의 최대 손실율을 초과했습니다") + .name("포트폴리오1") + .target("최대 손실율") .type("portfolio") .referenceId("1") .build(); @@ -260,7 +276,7 @@ void sendNotification_whenEmptyToken_thenDoNotSendNotification() { assertAll( () -> assertThat(response) .extracting("title", "content", "isRead", "type", "referenceId") - .containsExactly("포트폴리오", "포트폴리오1의 최대 손실율을 초과했습니다", false, "portfolio", "1"), + .containsExactly("포트폴리오", "포트폴리오1이(가) 최대 손실율에 도달했습니다", false, "portfolio", "1"), () -> assertThat(response) .extracting("sendMessageIds") .asList() @@ -280,46 +296,69 @@ private Member createMember() { } private List createNotifications(Member member) { - Notification notification1 = createNotification( + Notification notification1 = createStockTargetPriceNotification( "지정가", "삼성전자가 지정가 KRW60000에 도달했습니다", true, LocalDateTime.of(2024, 1, 22, 10, 10, 10), "stock", "005930", - member + member, + "삼성전자", + 60000L ); - Notification notification2 = createNotification( + Notification notification2 = createPortfolioNotification( "포트폴리오", "포트폴리오1의 목표 수익률을 달성했습니다", false, LocalDateTime.of(2024, 1, 23, 10, 10, 10), "portfolio", "1", - member + member, + "포트폴리오1", + PortfolioNotificationType.TARGET_GAIN ); - Notification notification3 = createNotification( + Notification notification3 = createPortfolioNotification( "포트폴리오", "포트폴리오2의 최대 손실율을 초과했습니다", false, LocalDateTime.of(2024, 1, 24, 10, 10, 10), "portfolio", "2", - member + member, + "포트폴리오2", + PortfolioNotificationType.MAX_LOSS ); return List.of(notification1, notification2, notification3); } - private Notification createNotification(String title, String content, boolean isRead, LocalDateTime createAt, - String type, String referenceId, Member member) { - return Notification.builder() + private Notification createPortfolioNotification(String title, String content, boolean isRead, + LocalDateTime createAt, String type, String referenceId, Member member, String portfolioName, + PortfolioNotificationType notificationType) { + return PortfolioNotification.builder() .title(title) - .content(content) .isRead(isRead) .createAt(createAt) .type(type) .referenceId(referenceId) .member(member) + .portfolioName(portfolioName) + .notificationType(notificationType) + .build(); + } + + private Notification createStockTargetPriceNotification(String title, String content, boolean isRead, + LocalDateTime createAt, + String type, String referenceId, Member member, String stockName, Long targetPrice) { + return StockTargetPriceNotification.builder() + .title(title) + .isRead(isRead) + .createAt(createAt) + .type(type) + .referenceId(referenceId) + .member(member) + .stockName(stockName) + .targetPrice(targetPrice) .build(); }