From 21f39d5c4b278bb2474204c575c8864c57ae3439 Mon Sep 17 00:00:00 2001 From: gs97ahn Date: Tue, 13 Feb 2024 22:29:05 +0900 Subject: [PATCH] [FEAT] add team leader position in createTeam API request --- .../api/controller/team/TeamController.java | 2 +- .../dto/team/request/TeamCreateRequest.java | 24 +- .../api/service/team/TeamService.java | 15 +- .../controller/team/TeamControllerTest.java | 136 ++++++---- .../api/service/team/TeamServiceTest.java | 255 ++++++------------ 5 files changed, 176 insertions(+), 256 deletions(-) diff --git a/src/main/java/com/gabojait/gabojaitspring/api/controller/team/TeamController.java b/src/main/java/com/gabojait/gabojaitspring/api/controller/team/TeamController.java index 149cf3e5..be2ac048 100644 --- a/src/main/java/com/gabojait/gabojaitspring/api/controller/team/TeamController.java +++ b/src/main/java/com/gabojait/gabojaitspring/api/controller/team/TeamController.java @@ -56,7 +56,7 @@ public class TeamController { "- 401 = TOKEN_UNAUTHENTICATED\n" + "- 403 = TOKEN_UNAUTHORIZED\n" + "- 404 = USER_NOT_FOUND\n" + - "- 409 = EXISTING_CURRENT_TEAM || NON_EXISTING_POSITION || TEAM_LEADER_POSITION_UNAVAILABLE\n" + + "- 409 = EXISTING_CURRENT_TEAM || TEAM_LEADER_POSITION_UNAVAILABLE\n" + "- 500 = SERVER_ERROR\n" + "- 503 = ONGOING_INSPECTION") @ApiResponses(value = { diff --git a/src/main/java/com/gabojait/gabojaitspring/api/dto/team/request/TeamCreateRequest.java b/src/main/java/com/gabojait/gabojaitspring/api/dto/team/request/TeamCreateRequest.java index 90a8a83c..7cbc3e22 100644 --- a/src/main/java/com/gabojait/gabojaitspring/api/dto/team/request/TeamCreateRequest.java +++ b/src/main/java/com/gabojait/gabojaitspring/api/dto/team/request/TeamCreateRequest.java @@ -2,12 +2,16 @@ import com.gabojait.gabojaitspring.domain.team.Team; import com.gabojait.gabojaitspring.domain.team.TeamMember; +import com.gabojait.gabojaitspring.domain.user.Position; import com.gabojait.gabojaitspring.domain.user.User; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.*; -import javax.validation.constraints.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.PositiveOrZero; +import javax.validation.constraints.Size; @Getter @Setter @@ -33,22 +37,28 @@ public class TeamCreateRequest { @Pattern(regexp = "^https\\:\\/\\/open\\.kakao\\.com\\/.+$", message = "오픈 채팅 URL은 카카오 오픈 채팅 형식만 가능합니다.") private String openChatUrl; - @ApiModelProperty(position = 5, required = true, value = "디자이너 최대 수") + @ApiModelProperty(position = 5, required = true, value = "포지션", example = "MANAGER", + allowableValues = "DESIGNER, BACKEND, FRONTEND, MANAGER") + @Pattern(regexp = "^(DESIGNER|BACKEND|FRONTEND|MANAGER|NONE)", + message = "포지션은 'DESIGNER', 'BACKEND', 'FRONTEND', 'MANAGER', 또는 'NONE' 중 하나여야 됩니다.") + private String position; + + @ApiModelProperty(position = 6, required = true, value = "디자이너 최대 수") @NotNull(message = "디자이너 최대 수는 필수 입력입니다.") @PositiveOrZero(message = "디자이너 최대 수는 0 또는 양수만 가능합니다.") private Byte designerMaxCnt; - @ApiModelProperty(position = 6, required = true, value = "백엔드 최대 수") + @ApiModelProperty(position = 7, required = true, value = "백엔드 최대 수") @NotNull(message = "백엔드 최대 수는 필수 입력입니다.") @PositiveOrZero(message = "백엔드 최대 수는 0 또는 양수만 가능합니다.") private Byte backendMaxCnt; - @ApiModelProperty(position = 7, required = true, value = "프런트 최대 수") + @ApiModelProperty(position = 8, required = true, value = "프런트 최대 수") @NotNull(message = "프런트 최대 수는 필수 입력입니다.") @PositiveOrZero(message = "프런트 최대 수는 0 또는 양수만 가능합니다.") private Byte frontendMaxCnt; - @ApiModelProperty(position = 8, required = true, value = "매니저 최대 수") + @ApiModelProperty(position = 9, required = true, value = "매니저 최대 수") @NotNull(message = "매니저 최대 수는 필수 입력입니다.") @PositiveOrZero(message = "매니저 최대 수는 0 또는 양수만 가능합니다.") private Byte managerMaxCnt; @@ -68,7 +78,7 @@ public Team toTeamEntity() { public TeamMember toTeamMemberEntity(User user, Team team) { return TeamMember.builder() - .position(user.getPosition()) + .position(Position.valueOf(this.position)) .isLeader(true) .user(user) .team(team) @@ -80,6 +90,7 @@ private TeamCreateRequest(String projectName, String projectDescription, String expectation, String openChatUrl, + String position, byte designerMaxCnt, byte backendMaxCnt, byte frontendMaxCnt, @@ -88,6 +99,7 @@ private TeamCreateRequest(String projectName, this.projectDescription = projectDescription; this.expectation = expectation; this.openChatUrl = openChatUrl; + this.position = position; this.designerMaxCnt = designerMaxCnt; this.backendMaxCnt = backendMaxCnt; this.frontendMaxCnt = frontendMaxCnt; diff --git a/src/main/java/com/gabojait/gabojaitspring/api/service/team/TeamService.java b/src/main/java/com/gabojait/gabojaitspring/api/service/team/TeamService.java index a13408c3..3912d24c 100644 --- a/src/main/java/com/gabojait/gabojaitspring/api/service/team/TeamService.java +++ b/src/main/java/com/gabojait/gabojaitspring/api/service/team/TeamService.java @@ -43,7 +43,7 @@ public class TeamService { /** * 팀 생성 | * 404(USER_NOT_FOUND) - * 409(EXISTING_CURRENT_TEAM / NON_EXISTING_POSITION / TEAM_LEADER_POSITION_UNAVAILABLE) + * 409(EXISTING_CURRENT_TEAM / TEAM_LEADER_POSITION_UNAVAILABLE) * @param userId 회원 식별자 * @param request 팀 생성 요청 * @return 팀 생성 응답 @@ -53,7 +53,6 @@ public TeamCreateResponse createTeam(long userId, TeamCreateRequest request) { User user = findUser(userId); validateHasNoCurrentTeam(user.getId()); - validateHasPosition(user); validateLeaderPosition(request, user); Team team = request.toTeamEntity(); @@ -290,16 +289,6 @@ private void validateHasNoCurrentTeam(long userId) { throw new CustomException(EXISTING_CURRENT_TEAM); } - /** - * 현재 포지션 존재 검증 | - * 409(NON_EXISTING_POSITION) - * @param user 회원 - */ - private void validateHasPosition(User user) { - if (!user.hasPosition()) - throw new CustomException(NON_EXISTING_POSITION); - } - /** * 현재 팀장 여부 검증 | * 403(REQUEST_FORBIDDEN) @@ -317,7 +306,7 @@ private void validateLeader(TeamMember teamMember) { * @param user 회원 */ private void validateLeaderPosition(TeamCreateRequest request, User user) { - switch (user.getPosition()) { + switch (Position.valueOf(request.getPosition())) { case DESIGNER: if (request.getDesignerMaxCnt() <= 0) throw new CustomException(TEAM_LEADER_POSITION_UNAVAILABLE); diff --git a/src/test/java/com/gabojait/gabojaitspring/api/controller/team/TeamControllerTest.java b/src/test/java/com/gabojait/gabojaitspring/api/controller/team/TeamControllerTest.java index 3cf66368..f79e003b 100644 --- a/src/test/java/com/gabojait/gabojaitspring/api/controller/team/TeamControllerTest.java +++ b/src/test/java/com/gabojait/gabojaitspring/api/controller/team/TeamControllerTest.java @@ -5,6 +5,7 @@ import com.gabojait.gabojaitspring.api.service.team.TeamService; import com.gabojait.gabojaitspring.config.auth.CustomAuthenticationEntryPoint; import com.gabojait.gabojaitspring.config.auth.JwtProvider; +import com.gabojait.gabojaitspring.domain.user.Position; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -57,11 +58,11 @@ void givenValid_whenCreateTeam_thenReturn201() throws Exception { } @Test - @DisplayName("디자이너 최대 수 미입력시 팀 생성을 하면 400을 반환한다.") - void givenBlankDesignerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("프로젝트명 20자 초과일시 팀 생성을 하면 400을 반환한다.") + void givenGreaterThan20SizeProjectName_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setDesignerMaxCnt(null); + request.setProjectName("가".repeat(21)); // when ResultActions actions = mockMvc.perform( @@ -74,17 +75,17 @@ void givenBlankDesignerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(DESIGNER_MAX_CNT_FIELD_REQUIRED.name())) + .value(PROJECT_NAME_LENGTH_INVALID.name())) .andExpect(jsonPath("$.responseMessage") - .value(DESIGNER_MAX_CNT_FIELD_REQUIRED.getMessage())); + .value(PROJECT_NAME_LENGTH_INVALID.getMessage())); } @Test - @DisplayName("백엔드 최대 수 미입력시 팀 생성을 하면 400을 반환한다.") - void givenBlankBackendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("프로젝트 설명 500자 초과일시 팀 생성을 하면 400을 반환한다.") + void givenGreaterThan500SizeProjectDescription_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setBackendMaxCnt(null); + request.setProjectDescription("가".repeat(501)); // when ResultActions actions = mockMvc.perform( @@ -97,17 +98,17 @@ void givenBlankBackendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(BACKEND_MAX_CNT_FIELD_REQUIRED.name())) + .value(PROJECT_DESCRIPTION_LENGTH_INVALID.name())) .andExpect(jsonPath("$.responseMessage") - .value(BACKEND_MAX_CNT_FIELD_REQUIRED.getMessage())); + .value(PROJECT_DESCRIPTION_LENGTH_INVALID.getMessage())); } @Test - @DisplayName("프런트 최대 수 미입력시 팀 생성을 하면 400을 반환한다.") - void givenBlankFrontendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("바라는 점 200자 초과일시 팀 생성을 하면 400을 반환한다.") + void givenGreaterThan200SizeExpectation_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setFrontendMaxCnt(null); + request.setExpectation("가".repeat(201)); // when ResultActions actions = mockMvc.perform( @@ -120,17 +121,17 @@ void givenBlankFrontendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(FRONTEND_MAX_CNT_FIELD_REQUIRED.name())) + .value(EXPECTATION_LENGTH_INVALID.name())) .andExpect(jsonPath("$.responseMessage") - .value(FRONTEND_MAX_CNT_FIELD_REQUIRED.getMessage())); + .value(EXPECTATION_LENGTH_INVALID.getMessage())); } @Test - @DisplayName("매니저 최대 수 미입력시 팀 생성을 하면 400을 반환한다.") - void givenBlankManagerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("오픈 채팅 링크 26자 미만일시 팀 생성을 하면 400을 반환한다.") + void givenLessThan26SizeOpenChatUrl_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setManagerMaxCnt(null); + request.setOpenChatUrl("https://open.kakao.com/o/"); // when ResultActions actions = mockMvc.perform( @@ -143,17 +144,17 @@ void givenBlankManagerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(MANAGER_MAX_CNT_FIELD_REQUIRED.name())) + .value(OPEN_CHAT_URL_LENGTH_INVALID.name())) .andExpect(jsonPath("$.responseMessage") - .value(MANAGER_MAX_CNT_FIELD_REQUIRED.getMessage())); + .value(OPEN_CHAT_URL_LENGTH_INVALID.getMessage())); } @Test - @DisplayName("프로젝트명 20자 초과일시 팀 생성을 하면 400을 반환한다.") - void givenGreaterThan20SizeProjectName_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("오픈 채팅 링크 100자 초과일시 팀 생성을 하면 400을 반환한다.") + void givenGreaterThan100SizeOpenChatUrl_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setProjectName("가".repeat(21)); + request.setOpenChatUrl("https://open.kakao.com/o/" + "a".repeat(76)); // when ResultActions actions = mockMvc.perform( @@ -166,17 +167,17 @@ void givenGreaterThan20SizeProjectName_whenCreateTeam_thenReturn400() throws Exc actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(PROJECT_NAME_LENGTH_INVALID.name())) + .value(OPEN_CHAT_URL_LENGTH_INVALID.name())) .andExpect(jsonPath("$.responseMessage") - .value(PROJECT_NAME_LENGTH_INVALID.getMessage())); + .value(OPEN_CHAT_URL_LENGTH_INVALID.getMessage())); } @Test - @DisplayName("프로젝트 설명 500자 초과일시 팀 생성을 하면 400을 반환한다.") - void givenGreaterThan500SizeProjectDescription_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("포지션 미입력시 팀 생성을 하면 400을 반환한다") + void givenBlankPosition_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setProjectDescription("가".repeat(501)); + request.setPosition(""); // when ResultActions actions = mockMvc.perform( @@ -189,17 +190,17 @@ void givenGreaterThan500SizeProjectDescription_whenCreateTeam_thenReturn400() th actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(PROJECT_DESCRIPTION_LENGTH_INVALID.name())) + .value(POSITION_TYPE_INVALID.name())) .andExpect(jsonPath("$.responseMessage") - .value(PROJECT_DESCRIPTION_LENGTH_INVALID.getMessage())); + .value(POSITION_TYPE_INVALID.getMessage())); } @Test - @DisplayName("바라는 점 200자 초과일시 팀 생성을 하면 400을 반환한다.") - void givenGreaterThan200SizeExpectation_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("디자이너 최대 수 미입력시 팀 생성을 하면 400을 반환한다.") + void givenBlankDesignerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setExpectation("가".repeat(201)); + request.setDesignerMaxCnt(null); // when ResultActions actions = mockMvc.perform( @@ -212,17 +213,17 @@ void givenGreaterThan200SizeExpectation_whenCreateTeam_thenReturn400() throws Ex actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(EXPECTATION_LENGTH_INVALID.name())) + .value(DESIGNER_MAX_CNT_FIELD_REQUIRED.name())) .andExpect(jsonPath("$.responseMessage") - .value(EXPECTATION_LENGTH_INVALID.getMessage())); + .value(DESIGNER_MAX_CNT_FIELD_REQUIRED.getMessage())); } @Test - @DisplayName("오픈 채팅 링크 26자 미만일시 팀 생성을 하면 400을 반환한다.") - void givenLessThan26SizeOpenChatUrl_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("디자이너 최대 수가 음수일시 팀 생성을 하면 400을 반환한다.") + void givenNegativeDesignerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setOpenChatUrl("https://open.kakao.com/o/"); + request.setDesignerMaxCnt((byte) -1); // when ResultActions actions = mockMvc.perform( @@ -235,17 +236,17 @@ void givenLessThan26SizeOpenChatUrl_whenCreateTeam_thenReturn400() throws Except actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(OPEN_CHAT_URL_LENGTH_INVALID.name())) + .value(DESIGNER_MAX_CNT_POSITIVE_OR_ZERO_ONLY.name())) .andExpect(jsonPath("$.responseMessage") - .value(OPEN_CHAT_URL_LENGTH_INVALID.getMessage())); + .value(DESIGNER_MAX_CNT_POSITIVE_OR_ZERO_ONLY.getMessage())); } @Test - @DisplayName("오픈 채팅 링크 100자 초과일시 팀 생성을 하면 400을 반환한다.") - void givenGreaterThan100SizeOpenChatUrl_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("백엔드 최대 수 미입력시 팀 생성을 하면 400을 반환한다.") + void givenBlankBackendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setOpenChatUrl("https://open.kakao.com/o/" + "a".repeat(76)); + request.setBackendMaxCnt(null); // when ResultActions actions = mockMvc.perform( @@ -258,17 +259,17 @@ void givenGreaterThan100SizeOpenChatUrl_whenCreateTeam_thenReturn400() throws Ex actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(OPEN_CHAT_URL_LENGTH_INVALID.name())) + .value(BACKEND_MAX_CNT_FIELD_REQUIRED.name())) .andExpect(jsonPath("$.responseMessage") - .value(OPEN_CHAT_URL_LENGTH_INVALID.getMessage())); + .value(BACKEND_MAX_CNT_FIELD_REQUIRED.getMessage())); } @Test - @DisplayName("디자이너 최대 수가 음수일시 팀 생성을 하면 400을 반환한다.") - void givenNegativeDesignerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("백엔드 최대 수가 음수일시 팀 생성을 하면 400을 반환한다.") + void givenNegativeBackendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setDesignerMaxCnt((byte) -1); + request.setBackendMaxCnt((byte) -1); // when ResultActions actions = mockMvc.perform( @@ -281,17 +282,17 @@ void givenNegativeDesignerMaxCnt_whenCreateTeam_thenReturn400() throws Exception actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(DESIGNER_MAX_CNT_POSITIVE_OR_ZERO_ONLY.name())) + .value(BACKEND_MAX_CNT_POSITIVE_OR_ZERO_ONLY.name())) .andExpect(jsonPath("$.responseMessage") - .value(DESIGNER_MAX_CNT_POSITIVE_OR_ZERO_ONLY.getMessage())); + .value(BACKEND_MAX_CNT_POSITIVE_OR_ZERO_ONLY.getMessage())); } @Test - @DisplayName("백엔드 최대 수가 음수일시 팀 생성을 하면 400을 반환한다.") - void givenNegativeBackendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { + @DisplayName("프런트 최대 수 미입력시 팀 생성을 하면 400을 반환한다.") + void givenBlankFrontendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { // given TeamCreateRequest request = createValidTeamCreateRequest(); - request.setBackendMaxCnt((byte) -1); + request.setFrontendMaxCnt(null); // when ResultActions actions = mockMvc.perform( @@ -304,11 +305,10 @@ void givenNegativeBackendMaxCnt_whenCreateTeam_thenReturn400() throws Exception actions.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.responseCode") - .value(BACKEND_MAX_CNT_POSITIVE_OR_ZERO_ONLY.name())) + .value(FRONTEND_MAX_CNT_FIELD_REQUIRED.name())) .andExpect(jsonPath("$.responseMessage") - .value(BACKEND_MAX_CNT_POSITIVE_OR_ZERO_ONLY.getMessage())); + .value(FRONTEND_MAX_CNT_FIELD_REQUIRED.getMessage())); } - @Test @DisplayName("프런트 최대 수가 음수일시 팀 생성을 하면 400을 반환한다.") void givenNegativeFrontendMaxCnt_whenCreateTeam_thenReturn400() throws Exception { @@ -332,6 +332,29 @@ void givenNegativeFrontendMaxCnt_whenCreateTeam_thenReturn400() throws Exception .value(FRONTEND_MAX_CNT_POSITIVE_OR_ZERO_ONLY.getMessage())); } + @Test + @DisplayName("매니저 최대 수 미입력시 팀 생성을 하면 400을 반환한다.") + void givenBlankManagerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { + // given + TeamCreateRequest request = createValidTeamCreateRequest(); + request.setManagerMaxCnt(null); + + // when + ResultActions actions = mockMvc.perform( + post("/api/v1/team") + .content(objectMapper.writeValueAsString(request)) + .contentType(APPLICATION_JSON) + ); + + // then + actions.andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.responseCode") + .value(MANAGER_MAX_CNT_FIELD_REQUIRED.name())) + .andExpect(jsonPath("$.responseMessage") + .value(MANAGER_MAX_CNT_FIELD_REQUIRED.getMessage())); + } + @Test @DisplayName("매니저 최대 수가 음수일시 팀 생성을 하면 400을 반환한다.") void givenNegativeManagerMaxCnt_whenCreateTeam_thenReturn400() throws Exception { @@ -1016,6 +1039,7 @@ private TeamCreateRequest createValidTeamCreateRequest() { .projectDescription("프로젝트 설명입니다.") .expectation("바라는 점입니다.") .openChatUrl("https://open.kakao.com/o/gabojait") + .position(Position.MANAGER.name()) .designerMaxCnt((byte) 2) .backendMaxCnt((byte) 2) .frontendMaxCnt((byte) 2) diff --git a/src/test/java/com/gabojait/gabojaitspring/api/service/team/TeamServiceTest.java b/src/test/java/com/gabojait/gabojaitspring/api/service/team/TeamServiceTest.java index f90dba17..703d261c 100644 --- a/src/test/java/com/gabojait/gabojaitspring/api/service/team/TeamServiceTest.java +++ b/src/test/java/com/gabojait/gabojaitspring/api/service/team/TeamServiceTest.java @@ -74,9 +74,9 @@ void givenValid_whenCreateTeam_theReturn(Position position, byte frontendCurrentCnt, byte managerCurrentCnt) { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", position); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); - TeamCreateRequest request = createValidTeamCreateRequest(); + TeamCreateRequest request = createValidTeamCreateRequest(position); // when TeamCreateResponse response = teamService.createTeam(user.getId(), request); @@ -95,94 +95,7 @@ void givenValid_whenCreateTeam_theReturn(Position position, () -> assertThat(response.getTeamMembers()) .extracting("userId", "username", "nickname", "position", "isLeader") .containsExactly( - tuple(user.getId(), user.getUsername(), user.getNickname(), user.getPosition(), true) - ) - ); - } - - @Test - @DisplayName("백엔드 포지션으로 팀 생성이 정상 작동한다") - void givenBackend_whenCreateTeam_theReturn() { - // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); - - TeamCreateRequest request = createValidTeamCreateRequest(); - - // when - TeamCreateResponse response = teamService.createTeam(user.getId(), request); - - // then - assertAll( - () -> assertThat(response) - .extracting("projectName", "designerCurrentCnt", "backendCurrentCnt", "frontendCurrentCnt", - "managerCurrentCnt", "designerMaxCnt", "backendMaxCnt", "frontendMaxCnt", "managerMaxCnt", - "projectDescription", "openChatUrl", "expectation") - .containsExactly(request.getProjectName(), (byte) 0, (byte) 1, (byte) 0, (byte) 0, - request.getDesignerMaxCnt(), request.getBackendMaxCnt(), request.getFrontendMaxCnt(), - request.getManagerMaxCnt(), request.getProjectDescription(), request.getOpenChatUrl(), - request.getExpectation()), - () -> assertThat(response.getTeamMembers()) - .extracting("userId", "username", "nickname", "position", "isLeader") - .containsExactly( - tuple(user.getId(), user.getUsername(), user.getNickname(), user.getPosition(), true) - ) - ); - } - - @Test - @DisplayName("프런트엔드 포지션으로 팀 생성이 정상 작동한다") - void givenFrontend_whenCreateTeam_theReturn() { - // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.FRONTEND); - - TeamCreateRequest request = createValidTeamCreateRequest(); - - // when - TeamCreateResponse response = teamService.createTeam(user.getId(), request); - - // then - assertAll( - () -> assertThat(response) - .extracting("projectName", "designerCurrentCnt", "backendCurrentCnt", "frontendCurrentCnt", - "managerCurrentCnt", "designerMaxCnt", "backendMaxCnt", "frontendMaxCnt", "managerMaxCnt", - "projectDescription", "openChatUrl", "expectation") - .containsExactly(request.getProjectName(), (byte) 0, (byte) 0, (byte) 1, (byte) 0, - request.getDesignerMaxCnt(), request.getBackendMaxCnt(), request.getFrontendMaxCnt(), - request.getManagerMaxCnt(), request.getProjectDescription(), request.getOpenChatUrl(), - request.getExpectation()), - () -> assertThat(response.getTeamMembers()) - .extracting("userId", "username", "nickname", "position", "isLeader") - .containsExactly( - tuple(user.getId(), user.getUsername(), user.getNickname(), user.getPosition(), true) - ) - ); - } - - @Test - @DisplayName("매니저 포지션으로 팀 생성이 정상 작동한다") - void givenManager_whenCreateTeam_theReturn() { - // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.MANAGER); - - TeamCreateRequest request = createValidTeamCreateRequest(); - - // when - TeamCreateResponse response = teamService.createTeam(user.getId(), request); - - // then - assertAll( - () -> assertThat(response) - .extracting("projectName", "designerCurrentCnt", "backendCurrentCnt", "frontendCurrentCnt", - "managerCurrentCnt", "designerMaxCnt", "backendMaxCnt", "frontendMaxCnt", "managerMaxCnt", - "projectDescription", "openChatUrl", "expectation") - .containsExactly(request.getProjectName(), (byte) 0, (byte) 0, (byte) 0, (byte) 1, - request.getDesignerMaxCnt(), request.getBackendMaxCnt(), request.getFrontendMaxCnt(), - request.getManagerMaxCnt(), request.getProjectDescription(), request.getOpenChatUrl(), - request.getExpectation()), - () -> assertThat(response.getTeamMembers()) - .extracting("userId", "username", "nickname", "position", "isLeader") - .containsExactly( - tuple(user.getId(), user.getUsername(), user.getNickname(), user.getPosition(), true) + tuple(user.getId(), user.getUsername(), user.getNickname(), position, true) ) ); } @@ -193,7 +106,7 @@ void givenNonExistingUser_whenCreateTeam_thenThrow() { // given long userId = 1L; - TeamCreateRequest request = createValidTeamCreateRequest(); + TeamCreateRequest request = createValidTeamCreateRequest(Position.MANAGER); // when & then assertThatThrownBy(() -> teamService.createTeam(userId, request)) @@ -206,11 +119,11 @@ void givenNonExistingUser_whenCreateTeam_thenThrow() { @DisplayName("소속된 팀이 있는 회원으로 팀을 생성시 예외가 발생한다") void givenExistingCurrentTeam_whenCreateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - TeamMember teamMember = createdSavedTeamMember(true, user, team); + TeamMember teamMember = createdSavedTeamMember(true, user, team, Position.MANAGER); - TeamCreateRequest request = createValidTeamCreateRequest(); + TeamCreateRequest request = createValidTeamCreateRequest(Position.MANAGER); // when & then assertThatThrownBy(() -> teamService.createTeam(user.getId(), request)) @@ -219,28 +132,13 @@ void givenExistingCurrentTeam_whenCreateTeam_thenThrow() { .isEqualTo(EXISTING_CURRENT_TEAM); } - @Test - @DisplayName("포지션이 없는 회원으로 팀 생성시 예외가 발생한다") - void givenNonePosition_whenCreateTeam_thenThrow() { - // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.NONE); - - TeamCreateRequest request = createValidTeamCreateRequest(); - - // when & then - assertThatThrownBy(() -> teamService.createTeam(user.getId(), request)) - .isInstanceOf(CustomException.class) - .extracting("errorCode") - .isEqualTo(NON_EXISTING_POSITION); - } - @Test @DisplayName("디자이너 최대 인원이 0인데 디자이너 포지션으로 팀 생성시 예외가 발생한다") void givenUnavailableDesigner_whenCreateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.DESIGNER); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); - TeamCreateRequest request = createValidTeamCreateRequest(); + TeamCreateRequest request = createValidTeamCreateRequest(Position.DESIGNER); request.setDesignerMaxCnt((byte) 0); // when & then @@ -254,9 +152,9 @@ void givenUnavailableDesigner_whenCreateTeam_thenThrow() { @DisplayName("백엔드 최대 인원이 0인데 백엔드 포지션으로 팀 생성시 예외가 발생한다") void givenUnavailableBackend_whenCreateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); - TeamCreateRequest request = createValidTeamCreateRequest(); + TeamCreateRequest request = createValidTeamCreateRequest(Position.BACKEND); request.setBackendMaxCnt((byte) 0); // when & then @@ -270,9 +168,9 @@ void givenUnavailableBackend_whenCreateTeam_thenThrow() { @DisplayName("프런트엔드 최대 인원이 0인데 백엔드 포지션으로 팀 생성시 예외가 발생한다") void givenUnavailableFrontend_whenCreateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.FRONTEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); - TeamCreateRequest request = createValidTeamCreateRequest(); + TeamCreateRequest request = createValidTeamCreateRequest(Position.FRONTEND); request.setFrontendMaxCnt((byte) 0); // when & then @@ -286,9 +184,9 @@ void givenUnavailableFrontend_whenCreateTeam_thenThrow() { @DisplayName("매니저 최대 인원이 0인데 백엔드 포지션으로 팀 생성시 예외가 발생한다") void givenUnavailableManager_whenCreateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.MANAGER); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); - TeamCreateRequest request = createValidTeamCreateRequest(); + TeamCreateRequest request = createValidTeamCreateRequest(Position.MANAGER); request.setManagerMaxCnt((byte) 0); // when & then @@ -302,9 +200,9 @@ void givenUnavailableManager_whenCreateTeam_thenThrow() { @DisplayName("팀 수정이 정상 작동한다") void givenValid_whenUpdateTeam_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - TeamMember teamMember = createdSavedTeamMember(true, user, team); + TeamMember teamMember = createdSavedTeamMember(true, user, team, Position.MANAGER); TeamUpdateRequest request = createValidTeamUpdateRequest(); @@ -317,7 +215,7 @@ void givenValid_whenUpdateTeam_thenReturn() { .extracting("projectName", "designerCurrentCnt", "backendCurrentCnt", "frontendCurrentCnt", "managerCurrentCnt", "designerMaxCnt", "backendMaxCnt", "frontendMaxCnt", "managerMaxCnt", "projectDescription", "openChatUrl", "expectation") - .containsExactly(request.getProjectName(), (byte) 0, (byte) 1, (byte) 0, (byte) 0, + .containsExactly(request.getProjectName(), (byte) 0, (byte) 0, (byte) 0, (byte) 1, request.getDesignerMaxCnt(), request.getBackendMaxCnt(), request.getFrontendMaxCnt(), request.getManagerMaxCnt(), request.getProjectDescription(), request.getOpenChatUrl(), request.getExpectation()), @@ -334,12 +232,12 @@ void givenValid_whenUpdateTeam_thenReturn() { @DisplayName("팀장이 아닌 회원이 팀 수정시 예외가 발생한다") void givenNonLeader_whenUpdateTeam_thenThrow() { // given - User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터일", Position.BACKEND); - User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터이", Position.BACKEND); + User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터일"); + User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터이"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user1, team); - createdSavedTeamMember(false, user2, team); + createdSavedTeamMember(true, user1, team, Position.MANAGER); + createdSavedTeamMember(false, user2, team, Position.BACKEND); TeamUpdateRequest request = createValidTeamUpdateRequest(); @@ -354,7 +252,7 @@ void givenNonLeader_whenUpdateTeam_thenThrow() { @DisplayName("현재 팀이 없는 회원이 팀 수정시 예외가 발생한다") void givenNoCurrentTeam_whenUpdateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); TeamUpdateRequest request = createValidTeamUpdateRequest(); @@ -369,10 +267,10 @@ void givenNoCurrentTeam_whenUpdateTeam_thenThrow() { @DisplayName("현재 디자이너 수보다 적은 디자이너 최대 수로 팀 수정시 예외가 발생한다") void givenUnavailableDesignerCnt_whenUpdateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.DESIGNER); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user, team); + createdSavedTeamMember(true, user, team, Position.DESIGNER); TeamUpdateRequest request = createValidTeamUpdateRequest(); request.setDesignerMaxCnt((byte) 0); @@ -388,10 +286,10 @@ void givenUnavailableDesignerCnt_whenUpdateTeam_thenThrow() { @DisplayName("현재 백엔드 수보다 적은 백엔드 최대 수로 팀 수정시 예외가 발생한다") void givenUnavailableBackendCnt_whenUpdateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user, team); + createdSavedTeamMember(true, user, team, Position.BACKEND); TeamUpdateRequest request = createValidTeamUpdateRequest(); request.setBackendMaxCnt((byte) 0); @@ -407,10 +305,10 @@ void givenUnavailableBackendCnt_whenUpdateTeam_thenThrow() { @DisplayName("현재 프런트엔드 수보다 적은 프런트엔드 최대 수로 팀 수정시 예외가 발생한다") void givenUnavailableFrontendCnt_whenUpdateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.FRONTEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user, team); + createdSavedTeamMember(true, user, team, Position.FRONTEND); TeamUpdateRequest request = createValidTeamUpdateRequest(); request.setFrontendMaxCnt((byte) 0); @@ -426,10 +324,10 @@ void givenUnavailableFrontendCnt_whenUpdateTeam_thenThrow() { @DisplayName("현재 매니저 수보다 적은 매니저 최대 수로 팀 수정시 예외가 발생한다") void givenUnavailableManagerCnt_whenUpdateTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.MANAGER); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user, team); + createdSavedTeamMember(true, user, team, Position.MANAGER); TeamUpdateRequest request = createValidTeamUpdateRequest(); request.setManagerMaxCnt((byte) 0); @@ -445,10 +343,10 @@ void givenUnavailableManagerCnt_whenUpdateTeam_thenThrow() { @DisplayName("현재 본인 팀 조회가 정상 작동한다") void givenValid_whenFindCurrentTeam_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.MANAGER); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - TeamMember teamMember = createdSavedTeamMember(true, user, team); + TeamMember teamMember = createdSavedTeamMember(true, user, team, Position.MANAGER); // when TeamMyCurrentResponse response = teamService.findCurrentTeam(user.getId()); @@ -476,7 +374,7 @@ void givenValid_whenFindCurrentTeam_thenReturn() { @DisplayName("현재 소속된 팀이 없는 회원 아이디로 현재 팀 조회시 예외가 발생한다") void givenNonExistingCurrentTeam_whenFindCurrentTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.MANAGER); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); // when & then assertThatThrownBy(() -> teamService.findCurrentTeam(user.getId())) @@ -489,9 +387,9 @@ void givenNonExistingCurrentTeam_whenFindCurrentTeam_thenThrow() { @DisplayName("내 팀 단건 조회가 정상 작동한다") void givenMyTeam_whenFindTeam_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - TeamMember teamMember = createdSavedTeamMember(true, user, team); + TeamMember teamMember = createdSavedTeamMember(true, user, team, Position.MANAGER); // when TeamFindResponse response = teamService.findOtherTeam(user.getId(), team.getId()); @@ -523,11 +421,11 @@ void givenMyTeam_whenFindTeam_thenReturn() { @DisplayName("내 팀이 아닌 팀 단건 조회가 정상 작동한다") void givenNotMyTeam_whenFindTeam_thenReturn() { // given - User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터일", Position.BACKEND); - User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터이", Position.BACKEND); + User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터일"); + User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터이"); Team team = createSavedTeam(); - TeamMember teamMember = createdSavedTeamMember(true, user1, team); + TeamMember teamMember = createdSavedTeamMember(true, user1, team, Position.MANAGER); Favorite favorite = createSavedFavorite(user2, null, team); Offer offer = createSavedOffer(team, user2, Position.MANAGER); @@ -561,7 +459,7 @@ void givenNotMyTeam_whenFindTeam_thenReturn() { @DisplayName("존재하지 않은 팀 식별자로 다른 팀 단건 조회시 예외가 발생한다") void givenNonExistingTeam_whenFindTeam_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); long teamId = 1L; // when & then @@ -613,9 +511,9 @@ void givenValid_whenFindPageTeam_thenReturn() { @DisplayName("팀원 모집 여부를 업데이트가 정상 작동한다") void givenValid_whenUpdateIsRecruiting_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user, team); + createdSavedTeamMember(true, user, team, Position.MANAGER); boolean isRecruiting = false; @@ -630,9 +528,9 @@ void givenValid_whenUpdateIsRecruiting_thenReturn() { @DisplayName("팀 리더가 아닌 회원으로 팀원 모집 여부 업데이트를 하면 예외가 발생한다") void givenNonLeader_whenUpdateIsRecruiting_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - createdSavedTeamMember(false, user, team); + createdSavedTeamMember(false, user, team, Position.MANAGER); boolean isRecruiting = false; @@ -647,7 +545,7 @@ void givenNonLeader_whenUpdateIsRecruiting_thenThrow() { @DisplayName("현재 소속 팀 없이 팀원 모집 여부 업데이트를 하면 예외가 발생한다") void givenNonExistingCurrentTeam_whenUpdateIsRecruiting_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); boolean isRecruiting = false; @@ -662,10 +560,10 @@ void givenNonExistingCurrentTeam_whenUpdateIsRecruiting_thenThrow() { @DisplayName("프로젝트 미완료로 프로젝트 종료가 정상 작동한다") void givenIncomplete_whenEndProject_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - TeamMember teamMember = createdSavedTeamMember(true, user, team); + TeamMember teamMember = createdSavedTeamMember(true, user, team, Position.MANAGER); LocalDateTime completeAt = LocalDateTime.now(); @@ -682,10 +580,10 @@ void givenIncomplete_whenEndProject_thenReturn() { @DisplayName("프로젝트 완료로 프로젝트 종료가 정상 작동한다") void givenComplete_whenEndProject_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - TeamMember teamMember = createdSavedTeamMember(true, user, team); + TeamMember teamMember = createdSavedTeamMember(true, user, team, Position.MANAGER); String projectUrl = "github.com/gabojait"; LocalDateTime completeAt = LocalDateTime.now(); @@ -703,12 +601,12 @@ void givenComplete_whenEndProject_thenReturn() { @DisplayName("팀원 추방이 정상 작동한다") void givenValid_whenFire_thenReturn() { // given - User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1", Position.BACKEND); - User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2", Position.DESIGNER); + User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1"); + User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user1, team); - createdSavedTeamMember(false, user2, team); + createdSavedTeamMember(true, user1, team, Position.MANAGER); + createdSavedTeamMember(false, user2, team, Position.BACKEND); // when teamService.fire(user1.getId(), user2.getId()); @@ -724,9 +622,8 @@ void givenValid_whenFire_thenReturn() { @DisplayName("존재하지 않은 팀장 식별자로 팀원 추방시 예외가 발생한다") void givenNonExistingTeamLeaderUserId_whenFire_thenThrow() { // given - User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1", Position.BACKEND); - User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2", Position.DESIGNER); - Team team = createSavedTeam(); + User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1"); + User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2"); // when & then assertThatThrownBy(() -> teamService.fire(user1.getId(), user2.getId())) @@ -739,12 +636,12 @@ void givenNonExistingTeamLeaderUserId_whenFire_thenThrow() { @DisplayName("회원이 팀장이 아닐시 팀원 추방을 하면 예외가 발생한다") void givenNonLeaderUsername_whenFire_thenThrow() { // given - User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1", Position.BACKEND); - User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2", Position.DESIGNER); + User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1"); + User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2"); Team team = createSavedTeam(); - createdSavedTeamMember(false, user1, team); - createdSavedTeamMember(false, user2, team); + createdSavedTeamMember(false, user1, team, Position.MANAGER); + createdSavedTeamMember(false, user2, team, Position.BACKEND); // when & then assertThatThrownBy(() -> teamService.fire(user1.getId(), user2.getId())) @@ -757,11 +654,11 @@ void givenNonLeaderUsername_whenFire_thenThrow() { @DisplayName("존재하지 않은 팀원 식별자로 팀원 추방시 예외가 발생한다") void givenNonExistingTeamMemberUserId_whenFire_thenThrow() { // given - User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1", Position.BACKEND); - User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2", Position.DESIGNER); + User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1"); + User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user1, team); + createdSavedTeamMember(true, user1, team, Position.MANAGER); // when & then assertThatThrownBy(() -> teamService.fire(user1.getId(), user2.getId())) @@ -774,8 +671,8 @@ void givenNonExistingTeamMemberUserId_whenFire_thenThrow() { @DisplayName("존재하지 않은 현재 팀을 가진 회원으로 팀원 추방을 하면 예외가 발생한다") void givenNonExistingCurrentTeam_whenFire_thenThrow() { // given - User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1", Position.BACKEND); - User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2", Position.DESIGNER); + User user1 = createSavedDefaultUser("tester1@gabojait.com", "tester1", "테스터1"); + User user2 = createSavedDefaultUser("tester2@gabojait.com", "tester2", "테스터2"); // when & then assertThatThrownBy(() -> teamService.fire(user1.getId(), user2.getId())) @@ -788,10 +685,10 @@ void givenNonExistingCurrentTeam_whenFire_thenThrow() { @DisplayName("팀을 나가면 정상 작동한다") void givenValid_whenLeave_thenReturn() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - TeamMember teamMember = createdSavedTeamMember(false, user, team); + TeamMember teamMember = createdSavedTeamMember(false, user, team, Position.MANAGER); // when teamService.leave(user.getId()); @@ -819,7 +716,7 @@ void givenNonExistingUser_whenLeave_thenThrow() { @DisplayName("현재 소속된 팀이 없는 회원으로 팀을 나가면 예외가 발생한다") void givenNonExistingCurrentTeam_whenLeave_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); // when & then assertThatThrownBy(() -> teamService.leave(user.getId())) @@ -832,10 +729,10 @@ void givenNonExistingCurrentTeam_whenLeave_thenThrow() { @DisplayName("팀장인 회원으로 팀을 나가면 예외가 발생한다") void givenTeamLeader_whenLeave_thenThrow() { // given - User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터", Position.BACKEND); + User user = createSavedDefaultUser("tester@gabojait.com", "tester", "테스터"); Team team = createSavedTeam(); - createdSavedTeamMember(true, user, team); + createdSavedTeamMember(true, user, team, Position.MANAGER); // when & then assertThatThrownBy(() -> teamService.leave(user.getId())) @@ -844,12 +741,13 @@ void givenTeamLeader_whenLeave_thenThrow() { .isEqualTo(TEAM_LEADER_UNAVAILABLE); } - private TeamCreateRequest createValidTeamCreateRequest() { + private TeamCreateRequest createValidTeamCreateRequest(Position position) { return TeamCreateRequest.builder() .projectName("가볼까잇") .projectDescription("가볼까잇 설명입니다.") .expectation("열정적인 팀원을 구해요.") .openChatUrl("kakao.com/o/gabojait") + .position(position.name()) .designerMaxCnt((byte) 5) .backendMaxCnt((byte) 5) .frontendMaxCnt((byte) 5) @@ -909,10 +807,10 @@ private Team createSavedTeam() { return team; } - private TeamMember createdSavedTeamMember(boolean isLeader, User user, Team team) { + private TeamMember createdSavedTeamMember(boolean isLeader, User user, Team team, Position position) { TeamMember teamMember = TeamMember.builder() .isLeader(isLeader) - .position(user.getPosition()) + .position(position) .user(user) .team(team) .build(); @@ -921,7 +819,7 @@ private TeamMember createdSavedTeamMember(boolean isLeader, User user, Team team return teamMember; } - private User createSavedDefaultUser(String email, String username, String nickname, Position position) { + private User createSavedDefaultUser(String email, String username, String nickname) { Contact contact = Contact.builder() .email(email) .verificationCode("000000") @@ -938,9 +836,6 @@ private User createSavedDefaultUser(String email, String username, String nickna .lastRequestAt(LocalDateTime.now()) .contact(contact) .build(); - user.updatePosition(position); - userRepository.save(user); - - return user; + return userRepository.save(user); } } \ No newline at end of file