diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestBoard.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestBoard.java index 2a1eeaaa..f9946eda 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestBoard.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestBoard.java @@ -22,7 +22,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import com.inhabas.api.domain.board.domain.BaseBoard; +import com.inhabas.api.domain.board.domain.NormalBoard; import com.inhabas.api.domain.board.domain.valueObject.Content; import com.inhabas.api.domain.board.domain.valueObject.Title; import com.inhabas.api.domain.contest.domain.valueObject.Association; @@ -35,7 +35,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @EntityListeners(AuditingEntityListener.class) -public class ContestBoard extends BaseBoard { +public class ContestBoard extends NormalBoard { @Enumerated(EnumType.STRING) @Column(name = "CONTEST_TYPE", nullable = false) diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/UpdateContestBoardDto.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/UpdateContestBoardDto.java deleted file mode 100644 index 884476c6..00000000 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/UpdateContestBoardDto.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.inhabas.api.domain.contest.dto; - -import java.time.LocalDate; - -import javax.validation.constraints.Future; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import com.inhabas.api.domain.contest.domain.ContestField; -import org.hibernate.validator.constraints.Length; -// 공모전 게시판 글 업데이트 - 삭제예정 - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -public class UpdateContestBoardDto { - @NotNull(message = "수정할 게시글을 선택해주세요.") - private Long id; - - @NotNull(message = "공모전 분야를 선택해주세요.") - private ContestField contestFieldId; - - @NotBlank(message = "제목을 입력하세요.") - @Length(max = 100, message = "제목은 최대 100자입니다.") - private String title; - - @NotBlank(message = "본문을 입력하세요.") - private String content; - - @Length(max = 100, message = "100자 이내로 작성해주세요.") - @NotBlank(message = "협회기관을 입력하세요.") - private String association; - - @Length(max = 500, message = "500자 이내로 작성해주세요.") - @NotBlank(message = "공모전 주제를 입력하세요.") - private String topic; - - @NotNull(message = "공모전 모집 시작일을 등록해주세요.") - private LocalDate dateContestStart; - - @NotNull(message = "공모전 모집 마감일을 등록해주세요.") - @Future(message = "이미 모집기간이 종료된 공모전은 등록할 수 없습니다.") - private LocalDate dateContestEnd; -} diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDtoTest.java new file mode 100644 index 00000000..f1bc51bb --- /dev/null +++ b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDtoTest.java @@ -0,0 +1,54 @@ +package com.inhabas.api.domain.contest.dto; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.LocalDate; + +import com.inhabas.api.domain.file.dto.FileDownloadDto; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class ContestBoardDtoTest { + + @DisplayName("올바른 공모전을 생성하고 검증한다.") + @Test + public void createContestBoardDto() { + + // given + Long id = 1L; + Long contestFieldId = 1L; + String title = "테스트 제목"; + String topic = "테스트 주제"; + String association = "테스트 협회"; + LocalDate dateContestStart = LocalDate.of(2024, 1, 1); + LocalDate dateContestEnd = LocalDate.of(2024, 3, 1); + FileDownloadDto thumbnail = new FileDownloadDto("thumbnail.jpg", "thumbnailUrl"); + + // when + ContestBoardDto contestBoardDto = + ContestBoardDto.builder() + .id(id) + .contestFieldId(contestFieldId) + .title(title) + .topic(topic) + .association(association) + .dateContestStart(dateContestStart) + .dateContestEnd(dateContestEnd) + .thumbnail(thumbnail) + .build(); + + // then + assertThat(contestBoardDto.getId()).isEqualTo(id); + assertThat(contestBoardDto.getContestFieldId()).isEqualTo(contestFieldId); + assertThat(contestBoardDto.getTitle()).isEqualTo(title); + assertThat(contestBoardDto.getTopic()).isEqualTo(topic); + assertThat(contestBoardDto.getAssociation()).isEqualTo(association); + assertThat(contestBoardDto.getDateContestStart()).isEqualTo(dateContestStart); + assertThat(contestBoardDto.getDateContestEnd()).isEqualTo(dateContestEnd); + assertThat(contestBoardDto.getThumbnail()).isEqualTo(thumbnail); + + long expectedDDay = LocalDate.now().until(dateContestEnd, java.time.temporal.ChronoUnit.DAYS); + assertThat(contestBoardDto.getDDay()).as("D-day가 일치하지 않습니다.").isEqualTo(expectedDDay); + } +} diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/UpdateContestBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/UpdateContestBoardDtoTest.java deleted file mode 100644 index 73810b56..00000000 --- a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/UpdateContestBoardDtoTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.inhabas.api.domain.contest.dto; - -// import static org.assertj.core.api.Assertions.assertThat; -// import static org.junit.jupiter.api.Assertions.assertEquals; - -// import java.time.LocalDate; -// import java.util.ArrayList; -// import java.util.List; -// import java.util.Set; - -// import javax.validation.ConstraintViolation; -// import javax.validation.Validation; -// import javax.validation.Validator; -// import javax.validation.ValidatorFactory; - -// import com.inhabas.api.domain.contest.dto.UpdateContestBoardDto; - -// import org.junit.jupiter.api.AfterAll; -// import org.junit.jupiter.api.BeforeAll; -// import org.junit.jupiter.api.DisplayName; -// import org.junit.jupiter.api.Test; - -// public class UpdateContestBoardDtoTest { -// private static ValidatorFactory validatorFactory; -// private static Validator validator; -// private static List errorMessage; - -// @BeforeAll -// public static void init() { -// validatorFactory = Validation.buildDefaultValidatorFactory(); -// validator = validatorFactory.getValidator(); - -// errorMessage = new ArrayList<>(); -// } - -// @AfterAll -// public static void close() { -// validatorFactory.close(); -// } - -// @DisplayName("공모전 게시글 수정 시 모든 필드가 null일 경우 테스트를 통과하지 못함.") -// @Test -// public void FieldsAreNullError() { -// // given -// UpdateContestBoardDto updateContestBoardDto = -// new UpdateContestBoardDto(null, null, null, null, null, null, null); - - // when -// Set> violations = -// validator.validate(updateContestBoardDto); -// violations.forEach(error -> errorMessage.add(error.getMessage())); - - // then -// assertThat(errorMessage) -// .contains( -// "수정할 게시글을 선택해주세요.", -// "제목을 입력하세요.", -// "본문을 입력하세요.", -// "협회기관을 입력하세요.", -// "공모전 주제를 입력하세요.", -// "공모전 모집 시작일을 등록해주세요.", -// "공모전 모집 마감일을 등록해주세요."); -// } - -// @DisplayName("공모전 게시글 수정 시 공백이 입력되었을 경우 테스트를 통과하지 못함.") -// @Test -// public void FieldsAreBlankError() { - // given -// UpdateContestBoardDto updateContestBoardDto = -// new UpdateContestBoardDto( -// 1, " ", " ", " ", " ", LocalDate.of(2022, 1, 1), LocalDate.of(2023, 2, 10)); - - // when -// Set> violations = -// validator.validate(updateContestBoardDto); -// violations.forEach(error -> errorMessage.add(error.getMessage())); - - // then -// assertThat(errorMessage).contains("제목을 입력하세요.", "본문을 입력하세요.", "협회기관을 입력하세요.", "공모전 주제를 -// 입력하세요."); -// } - -// @DisplayName("공모전 게시글 수정 시 제목, 협회기관명, 주제가 입력 길이를 초과하여 Validation 실패") -// @Test -// public void InputsAreExceededError() { - // given -// UpdateContestBoardDto updateContestBoardDto = -// new UpdateContestBoardDto( -// 1, -// "title".repeat(20) + ".", -// "content! Cucumber paste has to have a sun-dried, chilled sauerkraut component.", -// "Assoc".repeat(20) + ".", -// "topic".repeat(100) + ".", -// LocalDate.of(2022, 1, 1), -// LocalDate.of(9999, 3, 3)); - - // when -// Set> violations = -// validator.validate(updateContestBoardDto); -// violations.forEach(error -> errorMessage.add(error.getMessage())); - - // then -// assertEquals(3, violations.size()); -// assertThat(errorMessage) -// .containsOnly("제목은 최대 100자입니다.", "100자 이내로 작성해주세요.", "500자 이내로 작성해주세요."); -// } -// } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceTest.java index d06f6220..64f8e87e 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceTest.java @@ -111,30 +111,30 @@ public void deleteContestBoard() { // then(contestBoardRepository).should(times(1)).deleteById(any()); } - @DisplayName("공모전 게시글을 수정한다.") - @Test - public void updateContestBoard() { - // //given - // StudentId StudentId = new StudentId("12201863"); - // ContestBoard expectedContestBoard = - // new ContestBoard("title", "content", "association", "topic", - // LocalDate.of(2022, 1, 1), LocalDate.of(2022, 1, 26)) - // .writtenBy(StudentId); - // - // given(contestBoardRepository.save(any())).willReturn(expectedContestBoard); - // - // given(contestBoardRepository.findById(any())).willReturn(Optional.of(expectedContestBoard)); - // - // UpdateContestBoardDto updateContestBoardDto = new UpdateContestBoardDto(1, "수정된 제목", - // "수정된 내용", "수정된 협회기관명", "수정된 공모전 주제", LocalDate.of(2022, 1, 1), - // LocalDate.of(2022, 1, 26)); - // - // // when - // contestBoardService.update(StudentId, updateContestBoardDto); - // - // // then - // then(contestBoardRepository).should(times(1)).save(any()); - } + // @DisplayName("공모전 게시글을 수정한다.") + // @Test + // public void updateContestBoard() { + // //given + // StudentId StudentId = new StudentId("12201863"); + // ContestBoard expectedContestBoard = + // new ContestBoard("title", "content", "association", "topic", + // LocalDate.of(2022, 1, 1), LocalDate.of(2022, 1, 26)) + // .writtenBy(StudentId); + // + // given(contestBoardRepository.save(any())).willReturn(expectedContestBoard); + // + // given(contestBoardRepository.findById(any())).willReturn(Optional.of(expectedContestBoard)); + // + // UpdateContestBoardDto updateContestBoardDto = new UpdateContestBoardDto(1, "수정된 제목", + // "수정된 내용", "수정된 협회기관명", "수정된 공모전 주제", LocalDate.of(2022, 1, 1), + // LocalDate.of(2022, 1, 26)); + // + // // when + // contestBoardService.update(StudentId, updateContestBoardDto); + // + // // then + // then(contestBoardRepository).should(times(1)).save(any()); + // } @DisplayName("작성자가 아니면 수정할 수 없다.") @Test