Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix/165] 신고 등록 시 관리자 메일 발송 버그 수정 #166

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void sendEmail(String email, String subject, String templatePath, Map<Str
javaMailSender.send(message);

} catch (Exception e) {
log.error("이메일 전송에 실패했습니다.");
log.error("이메일 전송에 실패했습니다.", e);
throw new EmailException(ErrorCode.EMAIL_SEND_FAIL);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import org.hibernate.validator.constraints.Length;
Expand All @@ -27,6 +28,7 @@ public class ReportRequest {

@Min(value = 1, message = "path code는 1 이상의 값이어야 합니다.")
@Max(value = 3, message = "path code는 3 이하의 값이어야 합니다.")
@NotNull(message = "path code는 필수 값 입니다.")
Integer pathCode;

Long boardId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void handleSendReportEmailEvent(SendReportEmailEvent event) {
placeholders.put("REPORT_TO_MEMBER_ID", event.getToMemberId().toString());
placeholders.put("REPORT_PATH", report.getPath().name());
placeholders.put("REPORT_TYPE", reportService.getReportTypeString(event.getReportId()));
placeholders.put("REPORT_CONTENT", report.getContent());
placeholders.put("REPORT_CONTENT", report.getContent() != null ? report.getContent() : "null");

emailService.sendEmail(reportEmailTo, subject, reportTemplatePath, placeholders);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,37 @@ void addReportFailedWhenContentsSizeExceeds() throws Exception {
.andExpect(jsonPath("$.message").value("contents는 1000자 이내여야 합니다."));
}

@DisplayName("실패: 경로 코드 값이 없는 경우 에러 응답을 반환한다.")
@Test
void addReportFailedWhenPathCodeIsNull() throws Exception {
// given
List<Integer> reportCodeList = List.of(1, 2, 3);

ReportRequest request = ReportRequest.builder()
.reportCodeList(reportCodeList)
.contents("contents")
.pathCode(null)
.boardId(null)
.build();

ReportInsertResponse response = ReportInsertResponse.builder()
.reportId(1L)
.message("신고가 정상적으로 접수 되었습니다.")
.build();

given(reportFacadeService.addReport(any(Member.class), eq(TARGET_MEMBER_ID),
any(ReportRequest.class))).willReturn(response);

// when // then
mockMvc.perform(post(API_URL_PREFIX + "/{memberId}", TARGET_MEMBER_ID)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value("VALID_ERROR"))
.andExpect(jsonPath("$.message").value("path code는 필수 값 입니다."));

}

@DisplayName("실패: 경로 코드가 1보다 작은 경우 에러 응답을 반환한다.")
@Test
void addReportFailedWhenPathCodeLessThanMin() throws Exception {
Expand Down Expand Up @@ -277,6 +308,37 @@ void addReportFailedSucceeds() throws Exception {
.andExpect(jsonPath("$.data.message").value("신고가 정상적으로 접수 되었습니다."));
}

@DisplayName("텍스트, 게시글 id가 null일 때 성공")
@Test
void addReportFailedSucceedsWhenNull() throws Exception {
// given
List<Integer> reportCodeList = List.of(1, 2, 3);

ReportRequest request = ReportRequest.builder()
.reportCodeList(reportCodeList)
.contents(null)
.pathCode(1)
.boardId(null)
.build();

ReportInsertResponse response = ReportInsertResponse.builder()
.reportId(1L)
.message("신고가 정상적으로 접수 되었습니다.")
.build();

given(reportFacadeService.addReport(any(Member.class), eq(TARGET_MEMBER_ID),
any(ReportRequest.class))).willReturn(response);

// when // then
mockMvc.perform(post(API_URL_PREFIX + "/{memberId}", TARGET_MEMBER_ID)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("OK"))
.andExpect(jsonPath("$.data.reportId").value(1L))
.andExpect(jsonPath("$.data.message").value("신고가 정상적으로 접수 되었습니다."));
}

}

}
Loading