Skip to content

Commit

Permalink
#235 test: 테스트 코드 수정
Browse files Browse the repository at this point in the history
- Notification 엔티티 구조 변경으로 인한 테스트 코드 수정
  • Loading branch information
yonghwankim-dev committed Feb 21, 2024
1 parent ed09f9f commit a0deaa1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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();
Expand Down Expand Up @@ -310,7 +318,10 @@ private List<MemberNotification> 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")
Expand All @@ -319,7 +330,10 @@ private List<MemberNotification> 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")
Expand All @@ -328,7 +342,10 @@ private List<MemberNotification> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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();
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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()
Expand All @@ -280,46 +296,69 @@ private Member createMember() {
}

private List<Notification> 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();
}

Expand Down

0 comments on commit a0deaa1

Please sign in to comment.