|
| 1 | +package com.somemore.domains.recruitboard.service.validator; |
| 2 | + |
| 3 | +import com.somemore.domains.recruitboard.domain.RecruitBoard; |
| 4 | +import com.somemore.global.exception.BadRequestException; |
| 5 | +import org.junit.jupiter.api.DisplayName; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | +import org.junit.jupiter.params.ParameterizedTest; |
| 8 | +import org.junit.jupiter.params.provider.ValueSource; |
| 9 | + |
| 10 | +import java.time.LocalDateTime; |
| 11 | +import java.util.UUID; |
| 12 | + |
| 13 | +import static com.somemore.global.exception.ExceptionMessage.INVALID_RECRUIT_BOARD_TIME; |
| 14 | +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; |
| 15 | +import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime; |
| 16 | +import static com.somemore.support.fixture.RecruitBoardFixture.createRecruitBoard; |
| 17 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 18 | + |
| 19 | +class RecruitBoardValidatorTest { |
| 20 | + |
| 21 | + private final RecruitBoardValidator validator = new RecruitBoardValidator(); |
| 22 | + |
| 23 | + @DisplayName("봉사 종료 시간이 시작 시간과 같거나 빠르면, 봉사 모집글 생성 시 에러가 발생한다") |
| 24 | + @ParameterizedTest |
| 25 | + @ValueSource(longs = {0, -1}) |
| 26 | + void createRecruitBoardWithInValidVolunteerTime(long minutesOffset) { |
| 27 | + // given |
| 28 | + LocalDateTime now = createStartDateTime(); |
| 29 | + LocalDateTime endDateTime = now.plusMinutes(minutesOffset); |
| 30 | + |
| 31 | + // when & then |
| 32 | + assertThatThrownBy( |
| 33 | + () -> validator.validateRecruitBoardTime(now, endDateTime)) |
| 34 | + .isInstanceOf(BadRequestException.class) |
| 35 | + .hasMessage(INVALID_RECRUIT_BOARD_TIME.getMessage()); |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + @DisplayName("모집글 작성자가 아닌 경우 에러가 발생한다") |
| 40 | + @Test |
| 41 | + void validateAuthor() { |
| 42 | + // given |
| 43 | + UUID wrongCenterId = UUID.randomUUID(); |
| 44 | + RecruitBoard board = createRecruitBoard(UUID.randomUUID()); |
| 45 | + |
| 46 | + // when |
| 47 | + // then |
| 48 | + assertThatThrownBy( |
| 49 | + () -> validator.validateAuthor(board, wrongCenterId)) |
| 50 | + .isInstanceOf(BadRequestException.class) |
| 51 | + .hasMessage(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments