2828import io .crops .warmletter .domain .share .exception .SharePostNotFoundException ;
2929import io .crops .warmletter .domain .share .repository .SharePostRepository ;
3030import io .crops .warmletter .domain .timeline .dto .request .NotificationRequest ;
31- import io .crops .warmletter .domain .timeline .enums .AlarmType ;
32- import io .crops .warmletter .domain .timeline .facade .NotificationFacade ;
3331import io .crops .warmletter .global .error .exception .BusinessException ;
3432import org .junit .jupiter .api .BeforeEach ;
3533import org .junit .jupiter .api .DisplayName ;
@@ -66,6 +64,7 @@ class ReportServiceTest {
6664 private Report report ;
6765 private Member reportedMember ;
6866 @ InjectMocks private ReportService reportService ;
67+ @ Mock private ReportModerationService reportModerationService ;
6968
7069
7170 @ BeforeEach
@@ -90,7 +89,7 @@ void setUp() {
9089
9190 @ Test
9291 @ DisplayName ("정상적인 신고 등록 (LETTER)" )
93- void createReport_Success_Letter () {
92+ void createReport_Success_Letter () throws Exception {
9493 // Given: 신고 요청 생성
9594 CreateReportRequest request = new CreateReportRequest (
9695 ReportType .LETTER ,
@@ -138,6 +137,12 @@ void createReport_Success_Letter() {
138137 when (reportRepository .existsByLetterIdAndMemberId (1L , 1003L )).thenReturn (false );
139138 when (reportRepository .save (any (Report .class ))).thenReturn (report );
140139
140+ // 비동기 목 데이터 테스트 추가
141+ when (reportModerationService .moderateText (anyString (), any (), anyString ()))
142+ .thenReturn (Map .of ("status" , "RESOLVED" ));
143+ when (reportRepository .findById (report .getId ())).thenReturn (Optional .of (report ));
144+ when (memberRepository .findById (1003L )).thenReturn (Optional .of (reportedMember ));
145+
141146 // When: 신고 생성
142147 ReportResponse response = reportService .createReport (request );
143148
@@ -150,14 +155,15 @@ void createReport_Success_Letter() {
150155 // 추가 검증 (예: repository 호출 횟수 등)
151156 verify (authFacade , times (1 )).getCurrentUserId ();
152157 // verify(letterRepository, times(1)).existsById(1L); // 필요없으면 제거
153- verify (letterRepository , times (1 )).findById (1L );
158+ verify (letterRepository , times (3 )).findById (1L );
154159 verify (reportRepository , times (1 )).existsByLetterIdAndMemberId (1L , 1003L );
155- verify (reportRepository , times (1 )).save (any (Report .class ));
160+ verify (reportRepository , times (2 )).save (any (Report .class ));
161+ verify (reportModerationService , times (1 )).moderateText (anyString (), any (), anyString ()); // 비동기 메서드 호출 검증
156162 }
157163
158164 @ Test
159165 @ DisplayName ("정상적인 신고 등록 (EVENT_COMMENT)" )
160- void createReport_Success_EventComment () {
166+ void createReport_Success_EventComment () throws Exception {
161167 // Given: 신고 요청 생성
162168 CreateReportRequest request = new CreateReportRequest (
163169 ReportType .EVENT_COMMENT ,
@@ -191,6 +197,11 @@ void createReport_Success_EventComment() {
191197 when (reportRepository .existsByEventCommentIdAndMemberId (3L , 1003L )).thenReturn (false );
192198 when (reportRepository .save (any (Report .class ))).thenReturn (report );
193199
200+ // 비동기 목 데이터 테스트 추가
201+ when (reportModerationService .moderateText (anyString (), any (), anyString ()))
202+ .thenReturn (Map .of ("status" , "RESOLVED" ));
203+ when (reportRepository .findById (report .getId ())).thenReturn (Optional .of (report ));
204+
194205 // When: 신고 생성
195206 ReportResponse response = reportService .createReport (request );
196207
@@ -201,9 +212,10 @@ void createReport_Success_EventComment() {
201212
202213 // 추가 검증: 각 의존성 호출 횟수 확인
203214 verify (authFacade , times (1 )).getCurrentUserId ();
204- verify (eventCommentRepository , times (1 )).findById (3L );
215+ verify (eventCommentRepository , times (2 )).findById (3L );
205216 verify (reportRepository , times (1 )).existsByEventCommentIdAndMemberId (3L , 1003L );
206- verify (reportRepository , times (1 )).save (any (Report .class ));
217+ verify (reportRepository , times (2 )).save (any (Report .class ));
218+ verify (reportModerationService , times (1 )).moderateText (anyString (), any (), anyString ()); // 비동기 메서드 호출 검증
207219 }
208220
209221 @ Test
@@ -252,6 +264,11 @@ void createReport_Success_SharePost() {
252264 when (reportRepository .existsBySharePostIdAndMemberId (2L , 1003L )).thenReturn (false );
253265 when (reportRepository .save (any (Report .class ))).thenReturn (report );
254266
267+ // 비동기 목 데이터 테스트 추가
268+ when (reportModerationService .moderateText (anyString (), any (), anyString ()))
269+ .thenReturn (Map .of ("status" , "RESOLVED" ));
270+ when (reportRepository .findById (report .getId ())).thenReturn (Optional .of (report ));
271+
255272 // When: 신고 생성
256273 ReportResponse response = reportService .createReport (request );
257274
@@ -263,9 +280,10 @@ void createReport_Success_SharePost() {
263280
264281 // 각 의존성 호출 횟수 검증
265282 verify (authFacade , times (1 )).getCurrentUserId ();
266- verify (sharePostRepository , times (1 )).findById (2L );
283+ verify (sharePostRepository , times (2 )).findById (2L );
267284 verify (reportRepository , times (1 )).existsBySharePostIdAndMemberId (2L , 1003L );
268- verify (reportRepository , times (1 )).save (any (Report .class ));
285+ verify (reportRepository , times (2 )).save (any (Report .class ));
286+ verify (reportModerationService , times (1 )).moderateText (anyString (), any (), anyString ()); // 비동기 메서드 호출 검증
269287 }
270288
271289
0 commit comments