Skip to content

Commit

Permalink
Merge pull request #97 from Media-XI/feat/EventSchedule-생성시간이-종료시간보다-…
Browse files Browse the repository at this point in the history
…늦을경우-예외처리

feat: event schedule 생성시간이 종료시간보다 늦을경우 예외처리
  • Loading branch information
haroya01 authored Nov 25, 2023
2 parents b691b62 + 4c327ca commit 670ded9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ public class EventScheduleCreateDTO {
private List<ParticipantInformationDTO> participants;

public void checkTimeValidity() {
if (this.endDateTime == null) {
return;
}
if (this.startDateTime.equals(this.endDateTime)) {
throw new RuntimeException("시작시간과 종료시간이 같을 수 없습니다.");
}
if (this.startDateTime.isAfter(this.endDateTime)) {
throw new RuntimeException("시작시간이 종료시간보다 늦을 수 없습니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ private byte[] createImageFile() throws IOException {
.accept(MediaType.APPLICATION_JSON)
.characterEncoding("UTF-8"))
.andDo(print())
.andExpect(status().isCreated());
.andExpect(status().isBadRequest());
}

@DisplayName("이벤트 전체 조회 - 성공")
Expand Down Expand Up @@ -703,4 +703,37 @@ private byte[] createImageFile() throws IOException {
.andExpect(status().isBadRequest());
}

@WithMockCustomUser(username = "user", role = "CURATOR")
@DisplayName("스케줄 종료시간이 시작시간보다 빠를시")
@Test
public void 스케줄_생성시_종료시간이_시작시간보다_빠른경우() throws Exception {
createOrLoadMember("user", RoleStatus.CURATOR, "ROLE_CURATOR");

ExhbitionCreateDTO dto = mockCreateExhibitionDTO(1);
EventScheduleCreateDTO eventScheduleCreateDTO = dto.getSchedule().get(0);
eventScheduleCreateDTO.setEndDateTime(LocalDateTime.now().minusHours(1));
eventScheduleCreateDTO.setStartDateTime(LocalDateTime.now());

MockMultipartFile dtoFile =
new MockMultipartFile("dto", "", "application/json", objectMapper.writeValueAsBytes(dto));

MockMultipartFile mediaFile =
new MockMultipartFile("mediaFiles", "image.jpg", "image/jpg", createImageFile());

MockMultipartFile thumbnailFile =
new MockMultipartFile("thumbnailFile", "image.jpg", "image/jpg", createImageFile());

mockMvc
.perform(
multipart("/api/exhibitions")
.file(dtoFile)
.file(mediaFile)
.file(thumbnailFile)
.contentType(MediaType.MULTIPART_FORM_DATA)
.accept(MediaType.APPLICATION_JSON)
.characterEncoding("UTF-8"))
.andDo(print())
.andExpect(status().isBadRequest());
}

}

0 comments on commit 670ded9

Please sign in to comment.