|
| 1 | +package com.somemore.volunteerapply.service; |
| 2 | + |
| 3 | +import static com.somemore.common.fixture.RecruitBoardFixture.createCompletedRecruitBoard; |
| 4 | +import static com.somemore.common.fixture.RecruitBoardFixture.createRecruitBoard; |
| 5 | +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; |
| 6 | +import static com.somemore.recruitboard.domain.VolunteerCategory.OTHER; |
| 7 | +import static com.somemore.volunteerapply.domain.ApplyStatus.REJECTED; |
| 8 | +import static com.somemore.volunteerapply.domain.ApplyStatus.WAITING; |
| 9 | +import static org.assertj.core.api.Assertions.assertThat; |
| 10 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 11 | + |
| 12 | +import com.somemore.IntegrationTestSupport; |
| 13 | +import com.somemore.global.exception.BadRequestException; |
| 14 | +import com.somemore.global.exception.ExceptionMessage; |
| 15 | +import com.somemore.recruitboard.domain.RecruitBoard; |
| 16 | +import com.somemore.recruitboard.repository.RecruitBoardRepository; |
| 17 | +import com.somemore.volunteerapply.domain.VolunteerApply; |
| 18 | +import com.somemore.volunteerapply.repository.VolunteerApplyRepository; |
| 19 | +import java.util.UUID; |
| 20 | +import org.junit.jupiter.api.DisplayName; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; |
| 23 | + |
| 24 | +class RejectVolunteerApplyServiceTest extends IntegrationTestSupport { |
| 25 | + |
| 26 | + @Autowired |
| 27 | + private RejectVolunteerApplyService rejectVolunteerApplyService; |
| 28 | + |
| 29 | + @Autowired |
| 30 | + private VolunteerApplyRepository volunteerApplyRepository; |
| 31 | + |
| 32 | + @Autowired |
| 33 | + private RecruitBoardRepository recruitBoardRepository; |
| 34 | + |
| 35 | + @DisplayName("봉사 지원을 거절할 수 있다.") |
| 36 | + @Test |
| 37 | + void reject() { |
| 38 | + // given |
| 39 | + UUID centerId = UUID.randomUUID(); |
| 40 | + |
| 41 | + RecruitBoard board = createRecruitBoard(centerId); |
| 42 | + recruitBoardRepository.save(board); |
| 43 | + |
| 44 | + VolunteerApply apply = createApply(board.getId()); |
| 45 | + volunteerApplyRepository.save(apply); |
| 46 | + |
| 47 | + // when |
| 48 | + rejectVolunteerApplyService.reject(apply.getId(), centerId); |
| 49 | + |
| 50 | + // then |
| 51 | + VolunteerApply approve = volunteerApplyRepository.findById(apply.getId()).orElseThrow(); |
| 52 | + |
| 53 | + assertThat(approve.getStatus()).isEqualTo(REJECTED); |
| 54 | + } |
| 55 | + |
| 56 | + @DisplayName("자신이 작성한 모집글이 아닌 신청에 대해 거절할 경우 에러가 발생한다.") |
| 57 | + @Test |
| 58 | + void rejectWithWrongCenter() { |
| 59 | + // given |
| 60 | + RecruitBoard board = createRecruitBoard(UUID.randomUUID()); |
| 61 | + recruitBoardRepository.save(board); |
| 62 | + |
| 63 | + VolunteerApply apply = createApply(board.getId()); |
| 64 | + volunteerApplyRepository.save(apply); |
| 65 | + |
| 66 | + Long id = apply.getId(); |
| 67 | + UUID wrongCenterId = UUID.randomUUID(); |
| 68 | + |
| 69 | + // when |
| 70 | + // then |
| 71 | + assertThatThrownBy( |
| 72 | + () -> rejectVolunteerApplyService.reject(id, wrongCenterId) |
| 73 | + ).isInstanceOf(BadRequestException.class) |
| 74 | + .hasMessage(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); |
| 75 | + } |
| 76 | + |
| 77 | + @DisplayName("이미 완료된 봉사 모집에 대해 지원을 거절할 경우 에러가 발생 한다.") |
| 78 | + @Test |
| 79 | + void rejectWithAlreadyCompletedRecruit() { |
| 80 | + // given |
| 81 | + UUID centerId = UUID.randomUUID(); |
| 82 | + RecruitBoard board = createCompletedRecruitBoard(centerId, OTHER); |
| 83 | + recruitBoardRepository.save(board); |
| 84 | + |
| 85 | + VolunteerApply apply = createApply(board.getId()); |
| 86 | + volunteerApplyRepository.save(apply); |
| 87 | + |
| 88 | + Long id = apply.getId(); |
| 89 | + // when |
| 90 | + // then |
| 91 | + assertThatThrownBy( |
| 92 | + () -> rejectVolunteerApplyService.reject(id, centerId) |
| 93 | + ).isInstanceOf(BadRequestException.class) |
| 94 | + .hasMessage(ExceptionMessage.RECRUIT_BOARD_ALREADY_COMPLETED.getMessage()); |
| 95 | + } |
| 96 | + |
| 97 | + private VolunteerApply createApply(Long recruitBoardId) { |
| 98 | + return VolunteerApply.builder() |
| 99 | + .volunteerId(UUID.randomUUID()) |
| 100 | + .recruitBoardId(recruitBoardId) |
| 101 | + .status(WAITING) |
| 102 | + .attended(false) |
| 103 | + .build(); |
| 104 | + } |
| 105 | +} |
0 commit comments