diff --git a/backend/emm-sale/src/main/java/com/emmsale/event_publisher/CommentNotificationEvent.java b/backend/emm-sale/src/main/java/com/emmsale/event_publisher/CommentNotificationEvent.java new file mode 100644 index 000000000..869e0ccec --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/event_publisher/CommentNotificationEvent.java @@ -0,0 +1,37 @@ +package com.emmsale.event_publisher; + +import com.emmsale.comment.domain.Comment; +import com.emmsale.member.domain.Member; +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public class CommentNotificationEvent { + + private static final String UPDATE_NOTIFICATION_COMMENT_TYPE = "COMMENT"; + + private final Long receiverId; + private final Long redirectId; + private final LocalDateTime createdAt; + private final String notificationType; + private final String content; + private final String writer; + private final String writerImageUrl; + + public static CommentNotificationEvent of(final Comment comment, final Comment trigger) { + final Member member = comment.getMember(); + final Member triggerMember = trigger.getMember(); + + return new CommentNotificationEvent( + member.getId(), + trigger.getId(), + LocalDateTime.now(), + UPDATE_NOTIFICATION_COMMENT_TYPE, + trigger.getContent(), + triggerMember.getName(), + triggerMember.getImageUrl() + ); + } +} diff --git a/backend/emm-sale/src/main/java/com/emmsale/event_publisher/EventNotificationEvent.java b/backend/emm-sale/src/main/java/com/emmsale/event_publisher/EventNotificationEvent.java new file mode 100644 index 000000000..26af55ca3 --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/event_publisher/EventNotificationEvent.java @@ -0,0 +1,29 @@ +package com.emmsale.event_publisher; + +import com.emmsale.event.domain.Event; +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public class EventNotificationEvent { + + private static final String UPDATE_NOTIFICATION_EVENT_TYPE = "EVENT"; + + private final Long receiverId; + private final Long redirectId; + private final String notificationType; + private final LocalDateTime createdAt; + private final String title; + + public static EventNotificationEvent of(final Event event, final Long receiverId) { + return new EventNotificationEvent( + receiverId, + event.getId(), + UPDATE_NOTIFICATION_EVENT_TYPE, + LocalDateTime.now(), + event.getName() + ); + } +} diff --git a/backend/emm-sale/src/main/java/com/emmsale/event_publisher/EventPublisher.java b/backend/emm-sale/src/main/java/com/emmsale/event_publisher/EventPublisher.java index ef4ffd581..741117877 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/event_publisher/EventPublisher.java +++ b/backend/emm-sale/src/main/java/com/emmsale/event_publisher/EventPublisher.java @@ -31,7 +31,7 @@ public void publish(final Comment trigger, final Member loginMember) { .orElse(Collections.emptySet()); notificationCommentCandidates.stream() - .map(it -> UpdateNotificationEvent.of(it, trigger.getId())) + .map(it -> CommentNotificationEvent.of(it, trigger)) .forEach(applicationEventPublisher::publishEvent); } @@ -71,7 +71,7 @@ public void publish(final Event event) { private void publishEvent(final Event event, final List members) { members.forEach( it -> applicationEventPublisher.publishEvent( - UpdateNotificationEvent.of(event, it.getId()) + EventNotificationEvent.of(event, it.getId()) ) ); } diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java index 42447ec2a..2f53a4e67 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java @@ -6,12 +6,16 @@ import com.emmsale.event_publisher.MessageNotificationEvent; import com.emmsale.member.domain.MemberRepository; +import com.emmsale.notification.application.generator.CommentNotificationMessageGenerator; +import com.emmsale.notification.application.generator.EventNotificationMessageGenerator; import com.emmsale.notification.application.generator.MessageNotificationMessageGenerator; import com.emmsale.notification.application.generator.NotificationMessageGenerator; import com.emmsale.notification.application.generator.RequestNotificationMessageGenerator; import com.emmsale.notification.application.generator.UpdateNotificationMessageGenerator; import com.emmsale.notification.domain.FcmToken; import com.emmsale.notification.domain.FcmTokenRepository; +import com.emmsale.notification.domain.Notification; +import com.emmsale.notification.domain.NotificationType; import com.emmsale.notification.domain.RequestNotification; import com.emmsale.notification.domain.UpdateNotification; import com.emmsale.notification.exception.NotificationException; @@ -19,6 +23,8 @@ import com.google.auth.oauth2.GoogleCredentials; import java.io.IOException; import java.util.List; +import java.util.Map; +import java.util.function.Function; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -41,6 +47,12 @@ public class FirebaseCloudMessageClient { private static final String POSTFIX_FCM_REQUEST_URL = "/messages:send"; private static final String FIREBASE_KEY_PATH = "kerdy-submodule/firebase-kerdy.json"; private static final String GOOGLE_AUTH_URL = "https://www.googleapis.com/auth/cloud-platform"; + private static final Map> GENERATOR_MAP = + Map.of( + NotificationType.EVENT, EventNotificationMessageGenerator::new, + NotificationType.COMMENT, CommentNotificationMessageGenerator::new + ); + private final ObjectMapper objectMapper; private final MemberRepository memberRepository; @@ -71,6 +83,13 @@ public void sendMessageTo(final MessageNotificationEvent messageNotificationEven ); } + public void sendMessageTo(final Notification notification, final Long receiverId) { + sendMessageTo( + receiverId, + GENERATOR_MAP.get(notification.getType()).apply(notification) + ); + } + private void sendMessageTo( final Long receiverId, final NotificationMessageGenerator messageGenerator diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/NotificationEventListener.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/NotificationEventListener.java index 0f79a88c9..3c765c3e0 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/NotificationEventListener.java +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/NotificationEventListener.java @@ -1,10 +1,17 @@ package com.emmsale.notification.application; +import com.emmsale.event_publisher.CommentNotificationEvent; +import com.emmsale.event_publisher.EventNotificationEvent; import com.emmsale.event_publisher.MessageNotificationEvent; import com.emmsale.event_publisher.UpdateNotificationEvent; +import com.emmsale.notification.domain.Notification; +import com.emmsale.notification.domain.NotificationRepository; +import com.emmsale.notification.domain.NotificationType; import com.emmsale.notification.domain.UpdateNotification; import com.emmsale.notification.domain.UpdateNotificationRepository; import com.emmsale.notification.domain.UpdateNotificationType; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -19,6 +26,8 @@ public class NotificationEventListener { private final UpdateNotificationRepository updateNotificationRepository; private final FirebaseCloudMessageClient firebaseCloudMessageClient; + private final NotificationRepository notificationRepository; + private final ObjectMapper objectMapper; @Transactional(propagation = Propagation.REQUIRES_NEW) @TransactionalEventListener @@ -40,6 +49,50 @@ public void createUpdateNotification(final UpdateNotificationEvent updateNotific } } + @Transactional(propagation = Propagation.REQUIRES_NEW) + @TransactionalEventListener + public void createCommentNotification(final CommentNotificationEvent commentNotificationEvent) { + try { + final String jsonData = objectMapper.writeValueAsString(commentNotificationEvent); + + final Notification notification = notificationRepository.save( + new Notification(NotificationType.COMMENT, jsonData) + ); + + firebaseCloudMessageClient.sendMessageTo( + notification, + commentNotificationEvent.getReceiverId() + ); + + } catch (JsonProcessingException e) { + log.error("json 에러"); + } catch (Exception e) { + log.error("파이어베이스 관련 에러, 알림 재요청 필요, {}", e.getMessage(), e); + } + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + @TransactionalEventListener + public void createEventNotification(final EventNotificationEvent eventNotificationEvent) { + try { + final String jsonData = objectMapper.writeValueAsString(eventNotificationEvent); + + final Notification notification = notificationRepository.save( + new Notification(NotificationType.EVENT, jsonData) + ); + + firebaseCloudMessageClient.sendMessageTo( + notification, + eventNotificationEvent.getReceiverId() + ); + + } catch (JsonProcessingException e) { + log.error("json 에러"); + } catch (Exception e) { + log.error("파이어베이스 관련 에러, 알림 재요청 필요, {}", e.getMessage(), e); + } + } + @Transactional(propagation = Propagation.REQUIRES_NEW) @TransactionalEventListener public void createMessageNotification(final MessageNotificationEvent messageNotificationEvent) { diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/CommentNotificationMessage.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/CommentNotificationMessage.java new file mode 100644 index 000000000..cff19fbe8 --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/CommentNotificationMessage.java @@ -0,0 +1,35 @@ +package com.emmsale.notification.application.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public class CommentNotificationMessage { + + @JsonProperty("validate_only") + private final boolean validateOnly; + private final Message message; + + @RequiredArgsConstructor + @Getter + public static class Message { + + private final Data data; + private final String token; + } + + @RequiredArgsConstructor + @Getter + public static class Data { + + private final String receiverId; + private final String redirectId; + private final String notificationType; + private final String createdAt; + private final String content; + private final String writer; + private final String writerImageUrl; + } +} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/EventNotificationMessage.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/EventNotificationMessage.java new file mode 100644 index 000000000..62dac6c87 --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/EventNotificationMessage.java @@ -0,0 +1,33 @@ +package com.emmsale.notification.application.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public class EventNotificationMessage { + + @JsonProperty("validate_only") + private final boolean validateOnly; + private final Message message; + + @RequiredArgsConstructor + @Getter + public static class Message { + + private final Data data; + private final String token; + } + + @RequiredArgsConstructor + @Getter + public static class Data { + + private final String receiverId; + private final String redirectId; + private final String notificationType; + private final String createdAt; + private final String title; + } +} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/CommentNotificationMessageGenerator.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/CommentNotificationMessageGenerator.java new file mode 100644 index 000000000..aec6302b7 --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/CommentNotificationMessageGenerator.java @@ -0,0 +1,53 @@ +package com.emmsale.notification.application.generator; + +import static com.emmsale.notification.exception.NotificationExceptionType.BAD_REQUEST_MEMBER_ID; +import static com.emmsale.notification.exception.NotificationExceptionType.CONVERTING_JSON_ERROR; + +import com.emmsale.member.domain.MemberRepository; +import com.emmsale.notification.application.dto.CommentNotificationMessage; +import com.emmsale.notification.application.dto.CommentNotificationMessage.Data; +import com.emmsale.notification.application.dto.CommentNotificationMessage.Message; +import com.emmsale.notification.domain.Notification; +import com.emmsale.notification.exception.NotificationException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class CommentNotificationMessageGenerator implements NotificationMessageGenerator { + + private final Notification notification; + + @Override + public String makeMessage( + final String targetToken, + final ObjectMapper objectMapper, + final MemberRepository memberRepository + ) { + + final String jsonData = notification.getJsonData(); + + try { + + final Data data = objectMapper.readValue(jsonData, Data.class); + + validateIsExistedReceiver(memberRepository, Long.valueOf(data.getReceiverId())); + + final CommentNotificationMessage message = new CommentNotificationMessage( + DEFAULT_VALIDATE_ONLY, new Message(data, targetToken) + ); + + return objectMapper.writeValueAsString(message); + + } catch (JsonProcessingException e) { + throw new NotificationException(CONVERTING_JSON_ERROR); + } + } + + private void validateIsExistedReceiver(final MemberRepository memberRepository, + final Long receiverId) { + if (!memberRepository.existsById(receiverId)) { + throw new NotificationException(BAD_REQUEST_MEMBER_ID); + } + } +} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/EventNotificationMessageGenerator.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/EventNotificationMessageGenerator.java new file mode 100644 index 000000000..8ee14dfbe --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/EventNotificationMessageGenerator.java @@ -0,0 +1,52 @@ +package com.emmsale.notification.application.generator; + +import static com.emmsale.notification.application.dto.EventNotificationMessage.Data; +import static com.emmsale.notification.exception.NotificationExceptionType.BAD_REQUEST_MEMBER_ID; +import static com.emmsale.notification.exception.NotificationExceptionType.CONVERTING_JSON_ERROR; + +import com.emmsale.member.domain.MemberRepository; +import com.emmsale.notification.application.dto.EventNotificationMessage; +import com.emmsale.notification.application.dto.EventNotificationMessage.Message; +import com.emmsale.notification.domain.Notification; +import com.emmsale.notification.exception.NotificationException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class EventNotificationMessageGenerator implements NotificationMessageGenerator { + + private final Notification notification; + + @Override + public String makeMessage( + final String targetToken, + final ObjectMapper objectMapper, + final MemberRepository memberRepository + ) { + final String jsonData = notification.getJsonData(); + + try { + + final Data data = objectMapper.readValue(jsonData, Data.class); + + validateIsExistedReceiver(memberRepository, Long.valueOf(data.getReceiverId())); + + final EventNotificationMessage message = new EventNotificationMessage( + DEFAULT_VALIDATE_ONLY, new Message(data, targetToken) + ); + + return objectMapper.writeValueAsString(message); + + } catch (JsonProcessingException e) { + throw new NotificationException(CONVERTING_JSON_ERROR); + } + } + + private void validateIsExistedReceiver(final MemberRepository memberRepository, + final Long receiverId) { + if (!memberRepository.existsById(receiverId)) { + throw new NotificationException(BAD_REQUEST_MEMBER_ID); + } + } +} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/Notification.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/Notification.java new file mode 100644 index 000000000..313fb2af2 --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/Notification.java @@ -0,0 +1,37 @@ +package com.emmsale.notification.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Notification { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Enumerated(EnumType.STRING) + @Column(name = "type", nullable = false) + private NotificationType type; + + @Column(columnDefinition = "MEDIUMTEXT") + private String jsonData; + + private boolean isRead; + + public Notification(final NotificationType type, final String jsonData) { + this.type = type; + this.jsonData = jsonData; + this.isRead = false; + } +} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/NotificationRepository.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/NotificationRepository.java new file mode 100644 index 000000000..5f5440697 --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/NotificationRepository.java @@ -0,0 +1,7 @@ +package com.emmsale.notification.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationRepository extends JpaRepository { + +} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/NotificationType.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/NotificationType.java new file mode 100644 index 000000000..9c01454b8 --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/NotificationType.java @@ -0,0 +1,14 @@ +package com.emmsale.notification.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public enum NotificationType { + + COMMENT("comment"), + EVENT("event"); + + private final String type; +} diff --git a/backend/emm-sale/src/main/resources/schema.sql b/backend/emm-sale/src/main/resources/schema.sql index 73364c08e..0ec760bef 100644 --- a/backend/emm-sale/src/main/resources/schema.sql +++ b/backend/emm-sale/src/main/resources/schema.sql @@ -17,6 +17,7 @@ drop table if exists kerdy.message; drop table if exists kerdy.room; drop table if exists kerdy.feed; drop table if exists kerdy.image; +drop table if exists kerdy.notification; create table activity ( @@ -30,11 +31,11 @@ create table event id bigint auto_increment primary key, created_at datetime(6), updated_at datetime(6), - end_date datetime(6) not null, + end_date datetime(6) not null, information_url varchar(255) not null, location varchar(255) not null, name varchar(255) not null, - start_date datetime(6) not null, + start_date datetime(6) not null, image_url varchar(255), type varchar(20) not null ); @@ -60,7 +61,7 @@ create table comment is_deleted bit not null, event_id bigint not null, member_id bigint not null, - parent_id bigint null + parent_id bigint null ); create table member_activity @@ -128,7 +129,8 @@ alter table event_member add column updated_at datetime(6); -- 2023.08.08 17:04 -rename table notification TO request_notification; +rename +table notification TO request_notification; create table update_notification ( @@ -143,8 +145,8 @@ create table update_notification create table block ( id bigint auto_increment primary key, - block_member_id bigint not null, - request_member_id bigint not null, + block_member_id bigint not null, + request_member_id bigint not null, created_at datetime(6) null, updated_at datetime(6) null ); @@ -219,8 +221,8 @@ create table feed content varchar(1000) not null, event_id bigint not null, is_deleted bit not null, - created_at datetime(6) null, - updated_at datetime(6) null + created_at datetime(6) null, + updated_at datetime(6) null ); alter table comment rename column event_id to feed_id; @@ -246,3 +248,12 @@ alter table event -- 2023-09-20 20:25 alter table event add column organization varchar(50) not null; + +-- 2023-09-27 10:54 +create table notification +( + id bigint auto_increment primary key, + type varchar(20) not null, + json_data mediumtext not null, + is_read bit not null +) diff --git a/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceEventIntegrationTest.java b/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceEventIntegrationTest.java index 1509d3327..137c57626 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceEventIntegrationTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceEventIntegrationTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; @@ -19,6 +20,8 @@ import com.emmsale.helper.ServiceIntegrationTestHelper; import com.emmsale.member.domain.Member; import com.emmsale.member.domain.MemberRepository; +import com.emmsale.notification.domain.Notification; +import com.emmsale.notification.domain.NotificationRepository; import com.emmsale.notification.domain.UpdateNotification; import com.emmsale.notification.domain.UpdateNotificationRepository; import org.junit.jupiter.api.BeforeEach; @@ -40,6 +43,8 @@ class CommentCommandServiceEventIntegrationTest extends ServiceIntegrationTestHe private MemberRepository memberRepository; @Autowired private UpdateNotificationRepository updateNotificationRepository; + @Autowired + private NotificationRepository notificationRepository; private Member 댓글_작성자1; private Member 댓글_작성자2; private Feed feed; @@ -70,8 +75,8 @@ void test_publish_comment() throws Exception { //then assertAll( () -> verify(firebaseCloudMessageClient, times(1)).sendMessageTo( - any(UpdateNotification.class)), - () -> assertEquals(1, updateNotificationRepository.findAll().size()) + any(Notification.class), anyLong()), + () -> assertEquals(1, notificationRepository.findAll().size()) ); } @@ -93,8 +98,8 @@ void test_publish_comment_error_firebase() throws Exception { //then assertAll( () -> verify(firebaseCloudMessageClient, times(1)).sendMessageTo( - any(UpdateNotification.class)), - () -> assertEquals(1, updateNotificationRepository.findAll().size()) + any(Notification.class), anyLong()), + () -> assertEquals(1, notificationRepository.findAll().size()) ); } } diff --git a/backend/emm-sale/src/test/java/com/emmsale/event_publisher/EventPublisherTest.java b/backend/emm-sale/src/test/java/com/emmsale/event_publisher/EventPublisherTest.java index 6105a7cfb..fef2a5e4d 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/event_publisher/EventPublisherTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/event_publisher/EventPublisherTest.java @@ -98,14 +98,14 @@ void test_publish_event() throws Exception { eventPublisher.publish(savedEvent); //then - final ArgumentCaptor captor = ArgumentCaptor.forClass( - UpdateNotificationEvent.class); + final ArgumentCaptor captor = ArgumentCaptor.forClass( + EventNotificationEvent.class); verify(applicationEventPublisher, times(2)).publishEvent(captor.capture()); final List actual = captor.getAllValues() .stream() - .map(UpdateNotificationEvent::getReceiverId) + .map(EventNotificationEvent::getReceiverId) .collect(Collectors.toList()); assertThat(actual).containsExactlyInAnyOrderElementsOf(expected); @@ -191,7 +191,7 @@ void test_publish_comment_parent_children() throws Exception { //then verify(applicationEventPublisher, times(2)) - .publishEvent(any(UpdateNotificationEvent.class)); + .publishEvent(any(CommentNotificationEvent.class)); } @Test @@ -270,7 +270,7 @@ void test_publish_comment_not_notification_deletedComment() throws Exception { //then verify(applicationEventPublisher, times(1)) - .publishEvent(any(UpdateNotificationEvent.class)); + .publishEvent(any(CommentNotificationEvent.class)); } @Test @@ -305,7 +305,7 @@ void test_publish_comment_not_notification_deletedComment2() throws Exception { //then verify(applicationEventPublisher, times(2)) - .publishEvent(any(UpdateNotificationEvent.class)); + .publishEvent(any(CommentNotificationEvent.class)); } @Test diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/application/NotificationEventListenerTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/application/NotificationEventListenerTest.java index caa74f96c..f86abb9e3 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/application/NotificationEventListenerTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/notification/application/NotificationEventListenerTest.java @@ -11,8 +11,10 @@ import com.emmsale.event_publisher.MessageNotificationEvent; import com.emmsale.event_publisher.UpdateNotificationEvent; import com.emmsale.helper.ServiceIntegrationTestHelper; +import com.emmsale.notification.domain.NotificationRepository; import com.emmsale.notification.domain.UpdateNotification; import com.emmsale.notification.domain.UpdateNotificationRepository; +import com.fasterxml.jackson.databind.ObjectMapper; import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -26,13 +28,18 @@ class NotificationEventListenerTest extends ServiceIntegrationTestHelper { @Autowired private UpdateNotificationRepository updateNotificationRepository; private FirebaseCloudMessageClient mockingFirebaseCloudMessageClient; + @Autowired + private NotificationRepository notificationRepository; + @Autowired + private ObjectMapper objectMapper; @BeforeEach void setUp() { mockingFirebaseCloudMessageClient = mock(FirebaseCloudMessageClient.class); notificationEventListener = new NotificationEventListener( - updateNotificationRepository, mockingFirebaseCloudMessageClient + updateNotificationRepository, mockingFirebaseCloudMessageClient, + notificationRepository, objectMapper ); } diff --git a/backend/emm-sale/src/test/resources/data-test.sql b/backend/emm-sale/src/test/resources/data-test.sql index a01c23cea..ee8870afb 100644 --- a/backend/emm-sale/src/test/resources/data-test.sql +++ b/backend/emm-sale/src/test/resources/data-test.sql @@ -17,6 +17,7 @@ truncate table message; truncate table room; truncate table feed; truncate table image; +truncate table notification; insert into activity(id, type, name) values (1, 'CLUB', 'YAPP');