From 61bf7b1fead1c08157f7111ecc4b012f58f919b5 Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Fri, 8 Nov 2024 16:33:26 +0900 Subject: [PATCH] =?UTF-8?q?test(MeetingV2ServiceTest):=20=ED=96=89?= =?UTF-8?q?=EC=82=AC=20=EB=B0=8F=20=EC=9D=BC=EB=B0=98=20=EB=AA=A8=EC=9E=84?= =?UTF-8?q?=20=EC=8B=A0=EC=B2=AD=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2/service/MeetingV2ServiceTest.java | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/main/src/test/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceTest.java b/main/src/test/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceTest.java index c4d8e1ab..7f170904 100644 --- a/main/src/test/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceTest.java +++ b/main/src/test/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceTest.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; import org.sopt.makers.crew.main.entity.apply.Apply; import org.sopt.makers.crew.main.entity.apply.ApplyRepository; @@ -1710,6 +1711,122 @@ void applyMeeting_Fail_WhenIsLeader() { .isInstanceOf(BadRequestException.class) .hasMessage("모임장은 신청할 수 없습니다."); } + + @Test + @DisplayName("행사 카테고리에 일반 모임 신청 API로 호출 시 예외가 발생되어야 한다.") + void applyGeneralMeeting_WhenEventCategory_ShouldThrowException() { + // given + User leader = User.builder() + .name("모임장") + .orgId(1) + .activities(List.of(new UserActivityVO("안드로이드", 35))) + .profileImage("testProfileImage.jpg") + .phone("010-1234-5678") + .build(); + + userRepository.save(leader); + + Meeting meeting = Meeting.builder() + .user(leader) + .userId(leader.getId()) + .title("모임 지원 테스트") + .category(MeetingCategory.EVENT) + .imageURL(List.of(new ImageUrlVO(0, "testImage.jpg"))) + .startDate(LocalDateTime.of(2024, 4, 23, 0, 0, 0)) + .endDate(LocalDateTime.of(2029, 4, 27, 23, 59, 59)) + .capacity(20) + .desc("모임 지원 테스트입니다.") + .processDesc("테스트 진행 방식입니다.") + .mStartDate(LocalDateTime.of(2024, 11, 24, 0, 0, 0)) + .mEndDate(LocalDateTime.of(2024, 12, 24, 0, 0, 0)) + .leaderDesc("모임 리더 설명입니다.") + .note("유의사항입니다.") + .isMentorNeeded(false) + .canJoinOnlyActiveGeneration(false) + .createdGeneration(35) + .targetActiveGeneration(null) + .joinableParts(MeetingJoinablePart.values()) + .build(); + + meetingRepository.save(meeting); + + User applicant = User.builder() + .name("지원자 1") + .orgId(2) + .activities(List.of(new UserActivityVO("웹", 35))) + .profileImage("applicantProfile.jpg") + .phone("010-1234-5678") + .build(); + + userRepository.save(applicant); + + MeetingV2ApplyMeetingDto applyDto = new MeetingV2ApplyMeetingDto(meeting.getId(), "지원 동기"); + + // when & then + Assertions.assertThatThrownBy(() -> + meetingV2Service.applyGeneralMeeting(applyDto, applicant.getId()) + ).isInstanceOf(BadRequestException.class) + .hasMessageContaining("행사 모임에는 일반 모임 신청이 허용되지 않습니다."); + } + + @ParameterizedTest + @EnumSource(value = MeetingCategory.class, names = "EVENT", mode = EnumSource.Mode.EXCLUDE) + @DisplayName("행사 카테고리가 아닌 다른 카테고리로 행사 모임 신청 API로 호출 시 예외가 발생되어야 한다.") + void applyEventMeeting_WhenCategoryIsNotEvent_ShouldThrowException(MeetingCategory category) { + // given + User leader = User.builder() + .name("모임장") + .orgId(1) + .activities(List.of(new UserActivityVO("안드로이드", 35))) + .profileImage("testProfileImage.jpg") + .phone("010-1234-5678") + .build(); + + userRepository.save(leader); + + Meeting meeting = Meeting.builder() + .user(leader) + .userId(leader.getId()) + .title("모임 지원 테스트") + .category(category) + .imageURL(List.of(new ImageUrlVO(0, "testImage.jpg"))) + .startDate(LocalDateTime.of(2024, 4, 23, 0, 0, 0)) + .endDate(LocalDateTime.of(2029, 4, 27, 23, 59, 59)) + .capacity(20) + .desc("모임 지원 테스트입니다.") + .processDesc("테스트 진행 방식입니다.") + .mStartDate(LocalDateTime.of(2024, 11, 24, 0, 0, 0)) + .mEndDate(LocalDateTime.of(2024, 12, 24, 0, 0, 0)) + .leaderDesc("모임 리더 설명입니다.") + .note("유의사항입니다.") + .isMentorNeeded(false) + .canJoinOnlyActiveGeneration(false) + .createdGeneration(35) + .targetActiveGeneration(null) + .joinableParts(MeetingJoinablePart.values()) + .build(); + + meetingRepository.save(meeting); + + User applicant = User.builder() + .name("지원자 1") + .orgId(2) + .activities(List.of(new UserActivityVO("웹", 35))) + .profileImage("applicantProfile.jpg") + .phone("010-1234-5678") + .build(); + + userRepository.save(applicant); + + MeetingV2ApplyMeetingDto applyDto = new MeetingV2ApplyMeetingDto(meeting.getId(), "지원 동기"); + + // when & then + Assertions.assertThatThrownBy(() -> + meetingV2Service.applyEventMeeting(applyDto, applicant.getId()) + ).isInstanceOf(BadRequestException.class) + .hasMessageContaining("일반 모임에는 행사 모임 신청이 허용되지 않습니다."); + } + } @Nested