Skip to content

Commit

Permalink
Merge pull request gutanbug#75 from gutanbug/dev
Browse files Browse the repository at this point in the history
test gutanbug#65 : 미션 인증 글 승인 거부에 대한 테스트 코드 작성
  • Loading branch information
kjungw1025 authored Mar 21, 2024
2 parents 661a4de + b572166 commit 9cff4f0
Showing 1 changed file with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -138,4 +136,40 @@ void acceptMission_5() {
AlreadyMissionBoardAcceptedException exception = assertThrows(AlreadyMissionBoardAcceptedException.class, () -> adminService.acceptMission(UserRole.ADMIN, missionBoard.getId()));
assertEquals(exception.getMessageId(), "already.mission-board.accepted");
}

@Test
@DisplayName("미션 인증 글 승인 거부가 잘 되는지?")
void rejectMission_1() {
// given
Team team = TeamMock.create("팀1");
User user = UserMock.create(team, UserRole.MENTOR, passwordEncoder);
Mission mission = MissionMock.create();
MissionBoard missionBoard = MissionBoardMock.create(user, mission.getId(),false, RegisterStatus.IN_PROGRESS);
ReflectionTestUtils.setField(missionBoard, "id", 1L);

when(missionBoardRepository.findById(any())).thenReturn(Optional.of(missionBoard));

// when
adminService.rejectMission(UserRole.ADMIN, missionBoard.getId());

// then
assertEquals(missionBoard.getRegisterStatus(), RegisterStatus.REJECTED);
}

@Test
@DisplayName("미션 인증 글 승인 거부 - 승인 대기 중인 글이 아닐 때, 오류 메시지를 잘 반환하는지?")
void rejectMission_2() {
// given
Team team = TeamMock.create("팀1");
User user = UserMock.create(team, UserRole.MENTOR, passwordEncoder);
Mission mission = MissionMock.create();
MissionBoard missionBoard = MissionBoardMock.create(user, mission.getId(),false, RegisterStatus.ACCEPTED);
ReflectionTestUtils.setField(missionBoard, "id", 1L);

when(missionBoardRepository.findById(any())).thenReturn(Optional.of(missionBoard));

// when & then
MissionBoardNotInProgressException exception = assertThrows(MissionBoardNotInProgressException.class, () -> adminService.rejectMission(UserRole.ADMIN, missionBoard.getId()));
assertEquals(exception.getMessageId(), "failed.mission-board.in-progress");
}
}

0 comments on commit 9cff4f0

Please sign in to comment.