diff --git a/backend/src/main/java/site/coduo/retrospect/controller/error/RetrospectApiError.java b/backend/src/main/java/site/coduo/retrospect/controller/error/RetrospectApiError.java index 8dd69bfce..9fe24ab56 100644 --- a/backend/src/main/java/site/coduo/retrospect/controller/error/RetrospectApiError.java +++ b/backend/src/main/java/site/coduo/retrospect/controller/error/RetrospectApiError.java @@ -14,6 +14,7 @@ public enum RetrospectApiError { INVALID_RETROSPECT_INPUT_ERROR(HttpStatus.BAD_REQUEST, "잘못된 회고 입력 값입니다."), NOT_RETROSPECT_OWNER_ACCESS_ERROR(HttpStatus.FORBIDDEN, "회고 소유자 외 접근할 수 없는 작업입니다."), RETROSPECT_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "해당 요청의 회고가 존재하지 않습니다."), + MAX_RETROSPECT_LIMIT_REACHED_ERROR(HttpStatus.BAD_REQUEST, "회고는 최대 6개까지 추가할 수 있습니다."), ; private final HttpStatus httpStatus; diff --git a/backend/src/main/java/site/coduo/retrospect/exception/MaxRetrospectLimitException.java b/backend/src/main/java/site/coduo/retrospect/exception/MaxRetrospectLimitException.java new file mode 100644 index 000000000..581bcb1f8 --- /dev/null +++ b/backend/src/main/java/site/coduo/retrospect/exception/MaxRetrospectLimitException.java @@ -0,0 +1,12 @@ +package site.coduo.retrospect.exception; + +public class MaxRetrospectLimitException extends RetrospectException { + + public MaxRetrospectLimitException(final String message) { + super(message); + } + + public MaxRetrospectLimitException(final String message, final Throwable cause) { + super(message, cause); + } +} diff --git a/backend/src/main/java/site/coduo/retrospect/repository/RetrospectRepository.java b/backend/src/main/java/site/coduo/retrospect/repository/RetrospectRepository.java index c35398780..dd5abdccd 100644 --- a/backend/src/main/java/site/coduo/retrospect/repository/RetrospectRepository.java +++ b/backend/src/main/java/site/coduo/retrospect/repository/RetrospectRepository.java @@ -4,6 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository; +import site.coduo.pairroom.repository.PairRoomEntity; import site.coduo.pairroom.repository.PairRoomMemberEntity; public interface RetrospectRepository extends JpaRepository { @@ -12,4 +13,5 @@ public interface RetrospectRepository extends JpaRepository retrospectContentEntities = retrospect.getContents().getValues() diff --git a/backend/src/test/java/site/coduo/retrospect/service/RetrospectServiceTest.java b/backend/src/test/java/site/coduo/retrospect/service/RetrospectServiceTest.java index 7bc3e5a96..dc05960ef 100644 --- a/backend/src/test/java/site/coduo/retrospect/service/RetrospectServiceTest.java +++ b/backend/src/test/java/site/coduo/retrospect/service/RetrospectServiceTest.java @@ -31,6 +31,7 @@ import site.coduo.pairroom.repository.PairRoomRepository; import site.coduo.referencelink.repository.CategoryRepository; import site.coduo.retrospect.controller.response.FindRetrospectsResponse; +import site.coduo.retrospect.exception.MaxRetrospectLimitException; import site.coduo.retrospect.repository.RetrospectEntity; import site.coduo.retrospect.repository.RetrospectRepository; import site.coduo.timer.repository.TimerRepository; @@ -104,6 +105,40 @@ void createRetrospect() { assertThat(allByPairRoomMember).isNotEmpty(); } + @DisplayName("회고를 두 번 이상 저장하면 예외가 발생한다.") + @Test + void createTwiceRetrospect() { + // Given + final Member savedMember = memberRepository.save( + Member.builder() + .userId("userid") + .accessToken("access") + .loginId("login") + .username("username") + .profileImage("some image") + .build() + ); + final PairRoomEntity savedPairRoom = pairRoomRepository.save(PairRoomEntity.from( + new PairRoom(PairRoomStatus.IN_PROGRESS, + new Pair(new PairName("레디"), new PairName("파슬리")), + new MissionUrl("https://missionUrl.xxx"), + new AccessCode("123456"), + EASY_ACCESS_CODE_INK_REDDY) + )); + pairRoomMemberRepository.save(new PairRoomMemberEntity(savedPairRoom, savedMember)); + + final String credentialToken = jwtProvider.sign(savedMember.getUserId()); + final List answers = List.of("답변1", "답변2", "답변3", "답변4", "답변5", "답변6"); + retrospectService.createRetrospect(credentialToken, savedPairRoom.getAccessCode(), answers); + + // When && Then + assertThatThrownBy( + () -> retrospectService.createRetrospect(credentialToken, savedPairRoom.getAccessCode(), answers)) + .isInstanceOf(MaxRetrospectLimitException.class); + + } + + @DisplayName("입력된 페어룸 접근 코드에 대응되는 페어룸 정보가 존재하지 않는다면 예외를 발생시킨다.") @Test void notExistPairRoomByAccessCode() { @@ -300,9 +335,11 @@ void notExistRetrospectWithPairRoom() { final String credentialToken = jwtProvider.sign(savedMember.getUserId()); // When - retrospectService.createRetrospect(credentialToken, savedPairRoom.getAccessCode(), List.of("", "", "", "", "", "")); + retrospectService.createRetrospect(credentialToken, savedPairRoom.getAccessCode(), + List.of("", "", "", "", "", "")); - final boolean isExist = retrospectService.existRetrospectWithPairRoom(credentialToken, savedPairRoom.getAccessCode()); + final boolean isExist = retrospectService.existRetrospectWithPairRoom(credentialToken, + savedPairRoom.getAccessCode()); // Then assertThat(isExist).isFalse(); @@ -330,10 +367,12 @@ void oneExistRetrospectWithPairRoom() { pairRoomMemberRepository.save(new PairRoomMemberEntity(savedPairRoom, savedMember)); final String credentialToken = jwtProvider.sign(savedMember.getUserId()); - retrospectService.createRetrospect(credentialToken, savedPairRoom.getAccessCode(), List.of("답변!", "", "", "", "", "")); + retrospectService.createRetrospect(credentialToken, savedPairRoom.getAccessCode(), + List.of("답변!", "", "", "", "", "")); // When - final boolean isExist = retrospectService.existRetrospectWithPairRoom(credentialToken, savedPairRoom.getAccessCode()); + final boolean isExist = retrospectService.existRetrospectWithPairRoom(credentialToken, + savedPairRoom.getAccessCode()); // Then assertThat(isExist).isTrue();