diff --git a/src/main/java/com/backend/blooming/goal/application/GoalService.java b/src/main/java/com/backend/blooming/goal/application/GoalService.java index 7e27f397..ef259ca6 100644 --- a/src/main/java/com/backend/blooming/goal/application/GoalService.java +++ b/src/main/java/com/backend/blooming/goal/application/GoalService.java @@ -1,5 +1,6 @@ package com.backend.blooming.goal.application; +import com.backend.blooming.common.util.DayUtil; import com.backend.blooming.friend.infrastructure.repository.FriendRepository; import com.backend.blooming.goal.application.dto.CreateGoalDto; import com.backend.blooming.goal.application.dto.ReadAllGoalDto; @@ -12,13 +13,12 @@ import com.backend.blooming.goal.domain.Goal; import com.backend.blooming.goal.domain.GoalTeam; import com.backend.blooming.goal.infrastructure.repository.GoalRepository; +import com.backend.blooming.notification.application.NotificationService; import com.backend.blooming.stamp.domain.Stamp; import com.backend.blooming.stamp.infrastructure.repository.StampRepository; -import com.backend.blooming.notification.application.NotificationService; import com.backend.blooming.user.application.exception.NotFoundUserException; import com.backend.blooming.user.domain.User; import com.backend.blooming.user.infrastructure.repository.UserRepository; -import com.backend.blooming.common.util.DayUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -47,6 +47,9 @@ public Long createGoal(final CreateGoalDto createGoalDto) { } private List getUsers(final List userIds) { + if (userIds == null || userIds.isEmpty()) { + throw new InvalidGoalException.InvalidInvalidUsersSize(); + } return userRepository.findAllByUserIds(userIds); } diff --git a/src/main/java/com/backend/blooming/goal/domain/Goal.java b/src/main/java/com/backend/blooming/goal/domain/Goal.java index 3c073223..19b26235 100644 --- a/src/main/java/com/backend/blooming/goal/domain/Goal.java +++ b/src/main/java/com/backend/blooming/goal/domain/Goal.java @@ -29,10 +29,7 @@ public class Goal extends BaseTimeEntity { private static final String MEMO_DEFAULT = ""; - private static final int TEAMS_MAXIMUM_LENGTH = 5; private static final int MAX_LENGTH_OF_NAME = 50; - private static final int START_INDEX_OF_NAME = 0; - private static final int END_INDEX_OF_NAME = 50; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/test/java/com/backend/blooming/goal/application/GoalServiceTest.java b/src/test/java/com/backend/blooming/goal/application/GoalServiceTest.java index 6eb35358..d426eacf 100644 --- a/src/test/java/com/backend/blooming/goal/application/GoalServiceTest.java +++ b/src/test/java/com/backend/blooming/goal/application/GoalServiceTest.java @@ -1,6 +1,7 @@ package com.backend.blooming.goal.application; import com.backend.blooming.configuration.IsolateDatabase; +import com.backend.blooming.goal.application.dto.CreateGoalDto; import com.backend.blooming.goal.application.dto.ReadAllGoalDto; import com.backend.blooming.goal.application.dto.ReadGoalDetailDto; import com.backend.blooming.goal.application.exception.DeleteGoalForbiddenException; @@ -16,6 +17,8 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; import org.springframework.beans.factory.annotation.Autowired; import java.time.LocalDate; @@ -46,16 +49,34 @@ class GoalServiceTest extends GoalServiceTestFixture { assertThat(goalId).isPositive(); } + @ParameterizedTest + @NullAndEmptySource + void 골_생성시_골_참여자_목록이_null이거나_비어있는_경우_예외를_발생한다(final List teamUserIds) { + // given + final CreateGoalDto 골_참여자_목록이_비어있는_골_생성_dto = new CreateGoalDto( + 골_제목, + 골_메모, + 골_시작일, + 골_종료일, + 유효한_사용자_아이디, + teamUserIds + ); + + // when & then + assertThatThrownBy(() -> goalService.createGoal(골_참여자_목록이_비어있는_골_생성_dto)) + .isInstanceOf(InvalidGoalException.InvalidInvalidUsersSize.class); + } + @Test void 골_생성시_존재하지_않는_사용자가_관리자인_경우_예외를_발생한다() { - // when + // when & then assertThatThrownBy(() -> goalService.createGoal(존재하지_않는_사용자가_관리자인_골_생성_dto)) .isInstanceOf(NotFoundUserException.class); } @Test void 골_생성시_친구가_아닌_사용자가_참여자로_있는_경우_예외를_발생한다() { - // when + // when & then assertThatThrownBy(() -> goalService.createGoal(친구가_아닌_사용자가_참여자로_있는_골_생성_dto)) .isInstanceOf(InvalidGoalException.InvalidInvalidUserToParticipate.class); } diff --git a/src/test/java/com/backend/blooming/goal/presentation/GoalControllerTest.java b/src/test/java/com/backend/blooming/goal/presentation/GoalControllerTest.java index 7226d203..e0ad2d87 100644 --- a/src/test/java/com/backend/blooming/goal/presentation/GoalControllerTest.java +++ b/src/test/java/com/backend/blooming/goal/presentation/GoalControllerTest.java @@ -104,6 +104,26 @@ class GoalControllerTest extends GoalControllerTestFixture { )); } + @Test + void 골_생성시_골_참여자_목록이_null이거나_비어있는_경우_400_예외를_발생시킨다() throws Exception { + // given + given(tokenProvider.parseToken(액세스_토큰_타입, 액세스_토큰)).willReturn(사용자_토큰_정보); + given(userRepository.existsByIdAndDeletedIsFalse(사용자_토큰_정보.userId())).willReturn(true); + given(goalService.createGoal(유효한_골_생성_dto)) + .willThrow(new InvalidGoalException.InvalidInvalidUsersSize()); + + // when & then + mockMvc.perform(post("/goals") + .header("X-API-VERSION", 1) + .header(HttpHeaders.AUTHORIZATION, 액세스_토큰) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(요청한_골_dto)) + ).andExpectAll( + status().isBadRequest(), + jsonPath("$.message").exists() + ).andDo(print()); + } + @Test void 골_생성시_관리자와_친구가_아닌_사용자가_참여자로_있는_경우_400_예외를_발생시킨다() throws Exception { // given