|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
4 | 4 | import static org.assertj.core.api.Assertions.assertThatCode; |
5 | 5 |
|
| 6 | +import com.example.solidconnection.chat.domain.ChatMessage; |
| 7 | +import com.example.solidconnection.chat.domain.ChatRoom; |
| 8 | +import com.example.solidconnection.chat.fixture.ChatMessageFixture; |
| 9 | +import com.example.solidconnection.chat.fixture.ChatRoomFixture; |
6 | 10 | import com.example.solidconnection.common.exception.CustomException; |
7 | 11 | import com.example.solidconnection.common.exception.ErrorCode; |
8 | 12 | import com.example.solidconnection.community.board.domain.Board; |
@@ -45,18 +49,27 @@ class ReportServiceTest { |
45 | 49 | @Autowired |
46 | 50 | private ReportFixture reportFixture; |
47 | 51 |
|
| 52 | + @Autowired |
| 53 | + private ChatRoomFixture chatRoomFixture; |
| 54 | + |
| 55 | + @Autowired |
| 56 | + private ChatMessageFixture chatMessageFixture; |
| 57 | + |
48 | 58 | private SiteUser siteUser; |
49 | 59 | private Post post; |
| 60 | + private ChatMessage chatMessage; |
50 | 61 |
|
51 | 62 | @BeforeEach |
52 | 63 | void setUp() { |
53 | 64 | siteUser = siteUserFixture.사용자(); |
54 | 65 | Board board = boardFixture.자유게시판(); |
55 | 66 | post = postFixture.게시글(board, siteUser); |
| 67 | + ChatRoom chatRoom = chatRoomFixture.채팅방(false); |
| 68 | + chatMessage = chatMessageFixture.메시지("채팅", siteUser.getId(), chatRoom); |
56 | 69 | } |
57 | 70 |
|
58 | 71 | @Nested |
59 | | - class 신고_생성 { |
| 72 | + class 포스트_신고 { |
60 | 73 |
|
61 | 74 | @Test |
62 | 75 | void 정상적으로_신고한다() { |
@@ -96,4 +109,47 @@ class 신고_생성 { |
96 | 109 | .hasMessageContaining(ErrorCode.ALREADY_REPORTED_BY_CURRENT_USER.getMessage()); |
97 | 110 | } |
98 | 111 | } |
| 112 | + |
| 113 | + @Nested |
| 114 | + class 채팅_신고 { |
| 115 | + |
| 116 | + @Test |
| 117 | + void 정상적으로_신고한다() { |
| 118 | + // given |
| 119 | + ReportRequest request = new ReportRequest(ReportType.INSULT, TargetType.CHAT, chatMessage.getId()); |
| 120 | + |
| 121 | + // when |
| 122 | + reportService.createReport(siteUser.getId(), request); |
| 123 | + |
| 124 | + // then |
| 125 | + boolean isSaved = reportRepository.existsByReporterIdAndTargetTypeAndTargetId( |
| 126 | + siteUser.getId(), TargetType.CHAT, chatMessage.getId()); |
| 127 | + assertThat(isSaved).isTrue(); |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + void 신고_대상이_존재하지_않으면_예외가_발생한다() { |
| 132 | + // given |
| 133 | + long notExistingId = 999L; |
| 134 | + ReportRequest request = new ReportRequest(ReportType.SPAM, TargetType.CHAT, notExistingId); |
| 135 | + |
| 136 | + // when & then |
| 137 | + assertThatCode(() -> reportService.createReport(siteUser.getId(), request)) |
| 138 | + .isInstanceOf(CustomException.class) |
| 139 | + .hasMessageContaining(ErrorCode.REPORT_TARGET_NOT_FOUND.getMessage()); |
| 140 | + } |
| 141 | + |
| 142 | + @Test |
| 143 | + void 이미_신고한_경우_예외가_발생한다() { |
| 144 | + // given |
| 145 | + reportFixture.신고(siteUser.getId(), TargetType.CHAT, chatMessage.getId()); |
| 146 | + ReportRequest request = new ReportRequest(ReportType.INSULT, TargetType.CHAT, chatMessage.getId()); |
| 147 | + |
| 148 | + // when & then |
| 149 | + assertThatCode(() -> reportService.createReport(siteUser.getId(), request)) |
| 150 | + .isInstanceOf(CustomException.class) |
| 151 | + .hasMessageContaining(ErrorCode.ALREADY_REPORTED_BY_CURRENT_USER.getMessage()); |
| 152 | + } |
| 153 | + } |
99 | 154 | } |
| 155 | + |
0 commit comments