diff --git a/src/main/java/com/nexters/moyeomoyeo/common/constant/ExceptionInfo.java b/src/main/java/com/nexters/moyeomoyeo/common/constant/ExceptionInfo.java index 5d1ce79..ddd5bff 100644 --- a/src/main/java/com/nexters/moyeomoyeo/common/constant/ExceptionInfo.java +++ b/src/main/java/com/nexters/moyeomoyeo/common/constant/ExceptionInfo.java @@ -11,7 +11,7 @@ public enum ExceptionInfo { INVALID_TEAM_BUILDING_UUID("팀빌딩을 찾을 수 없습니다.", HttpStatus.BAD_REQUEST), INVALID_TEAM_UUID("팀을 찾을 수 없습니다.", HttpStatus.BAD_REQUEST), INVALID_USER_UUID("유저를 찾을 수 없습니다.", HttpStatus.BAD_REQUEST), - BAD_REQUEST_FOR_USER_PICK("해당 유저를 선택할 수 없습니다.", HttpStatus.BAD_REQUEST), + BAD_REQUEST_FOR_USER_PICK("유효하지 않은 유저 선택 요청입니다.", HttpStatus.BAD_REQUEST), ALREADY_JOINED_USER("다른 팀에 배정되어 있는 유저입니다.", HttpStatus.BAD_REQUEST), COMPLETED_TEAM_BUILDING("이미 종료된 팀빌딩입니다.", HttpStatus.BAD_REQUEST), INVALID_ADJUST_REQUEST("조정 라운드에서만 조정 가능합니다.", HttpStatus.BAD_REQUEST), diff --git a/src/main/java/com/nexters/moyeomoyeo/team_building/controller/UserSurveyController.java b/src/main/java/com/nexters/moyeomoyeo/team_building/controller/UserSurveyController.java index c946fee..368dba1 100644 --- a/src/main/java/com/nexters/moyeomoyeo/team_building/controller/UserSurveyController.java +++ b/src/main/java/com/nexters/moyeomoyeo/team_building/controller/UserSurveyController.java @@ -5,6 +5,7 @@ import com.nexters.moyeomoyeo.team_building.controller.dto.request.UserRequest; import com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamBuildingResponse; import com.nexters.moyeomoyeo.team_building.controller.dto.response.UserInfo; +import com.nexters.moyeomoyeo.team_building.service.TeamBuildingCoreService; import com.nexters.moyeomoyeo.team_building.service.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -28,7 +29,7 @@ public class UserSurveyController { private final UserService userService; - private final TeamBuildingService teamBuildingService; + private final TeamBuildingCoreService teamBuildingCoreService; @Operation(summary = "회원 생성 요청", description = """ 회원이 생성됩니다. \s @@ -48,6 +49,6 @@ public ResponseEntity createUser(@PathVariable(value = "teamBuildingUu @GetMapping("/{teamBuildingUuid}/teams") public ResponseEntity findTeamBuildingAndTeams( @PathVariable(value = "teamBuildingUuid") String teamBuildingUuid) { - return ResponseEntity.ok(teamBuildingService.findTeamBuildingAndTeams(teamBuildingUuid)); + return ResponseEntity.ok(teamBuildingCoreService.findTeamBuilding(teamBuildingUuid)); } } diff --git a/src/main/java/com/nexters/moyeomoyeo/team_building/domain/constant/RoundStatus.java b/src/main/java/com/nexters/moyeomoyeo/team_building/domain/constant/RoundStatus.java index 2579d62..5b76344 100644 --- a/src/main/java/com/nexters/moyeomoyeo/team_building/domain/constant/RoundStatus.java +++ b/src/main/java/com/nexters/moyeomoyeo/team_building/domain/constant/RoundStatus.java @@ -1,12 +1,13 @@ package com.nexters.moyeomoyeo.team_building.domain.constant; +import java.util.List; import lombok.Getter; public enum RoundStatus { COMPLETE(6, null), ADJUSTED_ROUND(5, COMPLETE), - FORTH_ROUND(4, ADJUSTED_ROUND), - THIRD_ROUND(3, FORTH_ROUND), + FOURTH_ROUND(4, ADJUSTED_ROUND), + THIRD_ROUND(3, FOURTH_ROUND), SECOND_ROUND(2, THIRD_ROUND), FIRST_ROUND(1, SECOND_ROUND), START(0, FIRST_ROUND) @@ -22,4 +23,8 @@ public enum RoundStatus { this.order = order; this.nextStatus = nextStatus; } + + public static boolean isPickUserPossible(RoundStatus roundStatus) { + return List.of(FIRST_ROUND, SECOND_ROUND, THIRD_ROUND, FOURTH_ROUND).contains(roundStatus); + } } diff --git a/src/main/java/com/nexters/moyeomoyeo/team_building/domain/entity/Team.java b/src/main/java/com/nexters/moyeomoyeo/team_building/domain/entity/Team.java index 611f32a..9373072 100644 --- a/src/main/java/com/nexters/moyeomoyeo/team_building/domain/entity/Team.java +++ b/src/main/java/com/nexters/moyeomoyeo/team_building/domain/entity/Team.java @@ -67,6 +67,5 @@ public void nextRound() { public void addTeamBuilding(TeamBuilding teamBuilding) { this.teamBuilding = teamBuilding; - this.teamBuilding.getTeams().add(this); } } diff --git a/src/main/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreService.java b/src/main/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreService.java index af36514..ef4d2a5 100644 --- a/src/main/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreService.java +++ b/src/main/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreService.java @@ -103,7 +103,6 @@ public UserPickResponse pickUsers(String teamBuildingUuid, String teamUuid, User validateRequest(teamBuildingRoundStatus, team, pickedUsers); addUserAndMoveTeamRound(team, pickedUsers); - moveTeamBuildingRoundIfAllSelected(teamBuilding); broadcastPickedUsers(teamBuilding.getUuid(), team.getUuid(), team.getName(), userUuids); @@ -132,8 +131,8 @@ private static void addUserAndMoveTeamRound(Team targetTeam, List pickedUs } private static void validateRequest(RoundStatus teamBuildingRoundStatus, Team targetTeam, List pickedUsers) { - if (RoundStatus.COMPLETE == teamBuildingRoundStatus) { - throw ExceptionInfo.COMPLETED_TEAM_BUILDING.exception(); + if (!RoundStatus.isPickUserPossible(teamBuildingRoundStatus)) { + throw ExceptionInfo.BAD_REQUEST_FOR_USER_PICK.exception(); } if (isSelectDone(teamBuildingRoundStatus, targetTeam.getRoundStatus())) { diff --git a/src/main/java/com/nexters/moyeomoyeo/team_building/service/UserService.java b/src/main/java/com/nexters/moyeomoyeo/team_building/service/UserService.java index 14a770c..bfe7f7c 100644 --- a/src/main/java/com/nexters/moyeomoyeo/team_building/service/UserService.java +++ b/src/main/java/com/nexters/moyeomoyeo/team_building/service/UserService.java @@ -20,7 +20,7 @@ public class UserService { private final NotificationService notificationService; private final UserRepository userRepository; - public static User makeUser(String teamBuildingUuid, UserRequest request) { + private static User makeUser(String teamBuildingUuid, UserRequest request) { return User.builder() .name(request.getName()) .position(request.getPosition()) @@ -44,13 +44,11 @@ public UserInfo createUser(String teamBuildingUuid, UserRequest request) { return userInfo; } - @Transactional public void deleteUser(String teamBuildingUuid, String userUuid) { final User targetUser = findByUuid(userUuid); userRepository.delete(targetUser); notificationService.broadcast(teamBuildingUuid, "delete-user", userUuid); - } public User findByUuid(String userUuid) { diff --git a/src/test/java/com/nexters/moyeomoyeo/team_building/fixture/FixtureTeamBuilding.java b/src/test/java/com/nexters/moyeomoyeo/team_building/fixture/FixtureTeamBuilding.java new file mode 100644 index 0000000..5944ae1 --- /dev/null +++ b/src/test/java/com/nexters/moyeomoyeo/team_building/fixture/FixtureTeamBuilding.java @@ -0,0 +1,38 @@ +package com.nexters.moyeomoyeo.team_building.fixture; + +import com.nexters.moyeomoyeo.team_building.domain.constant.Position; +import com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus; +import com.nexters.moyeomoyeo.team_building.domain.entity.Team; +import com.nexters.moyeomoyeo.team_building.domain.entity.TeamBuilding; +import java.util.List; + +public class FixtureTeamBuilding { + + public static TeamBuilding teamBuilding(RoundStatus roundStatus) { + return TeamBuilding.builder() + .roundStatus(roundStatus) + .name("넥스터즈 팀빌딩") + .teams(List.of( + Team.builder() + .name("team1") + .pmPosition(Position.IOS) + .roundStatus(roundStatus) + .build(), + Team.builder() + .name("team2") + .pmPosition(Position.ANDROID) + .roundStatus(roundStatus) + .build(), + Team.builder() + .name("team3") + .pmPosition(Position.FRONT_END) + .roundStatus(roundStatus) + .build(), + Team.builder() + .name("team4") + .pmPosition(Position.BACK_END) + .roundStatus(roundStatus) + .build())) + .build(); + } +} diff --git a/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingAdminServiceTest.java b/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingAdminServiceTest.java new file mode 100644 index 0000000..73b3f1a --- /dev/null +++ b/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingAdminServiceTest.java @@ -0,0 +1,129 @@ +package com.nexters.moyeomoyeo.team_building.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.BDDMockito.given; + +import com.nexters.moyeomoyeo.MoyeoMoyeoTest; +import com.nexters.moyeomoyeo.common.constant.ExceptionInfo; +import com.nexters.moyeomoyeo.common.exception.vo.CustomException; +import com.nexters.moyeomoyeo.team_building.controller.dto.request.TeamBuildingRequest; +import com.nexters.moyeomoyeo.team_building.controller.dto.request.TeamRequest; +import com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamBuildingResponse; +import com.nexters.moyeomoyeo.team_building.controller.dto.response.UserInfo; +import com.nexters.moyeomoyeo.team_building.domain.constant.Position; +import com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus; +import com.nexters.moyeomoyeo.team_building.domain.entity.Team; +import com.nexters.moyeomoyeo.team_building.domain.entity.TeamBuilding; +import com.nexters.moyeomoyeo.team_building.domain.entity.User; +import com.nexters.moyeomoyeo.team_building.domain.repository.TeamBuildingRepository; +import com.nexters.moyeomoyeo.team_building.domain.repository.UserRepository; +import com.nexters.moyeomoyeo.team_building.fixture.FixtureTeamBuilding; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@MoyeoMoyeoTest +class TeamBuildingAdminServiceTest { + + @Autowired + private TeamBuildingAdminService sut; + + @Autowired + private TeamBuildingRepository teamBuildingRepository; + + @Autowired + private UserRepository userRepository; + + @Test + void createTeamBuilding() { + final TeamBuildingResponse teamBuildingResponse = sut.createTeamBuilding(TeamBuildingRequest.builder() + .name("넥스터즈 팀빌딩이에요") + .teams(List.of( + TeamRequest.builder() + .name("team1") + .pmName("pm1") + .pmPosition(Position.FRONT_END) + .build(), + TeamRequest.builder() + .name("team2") + .pmName("pm2") + .pmPosition(Position.BACK_END) + .build())) + .build());; + + assertThat(teamBuildingResponse.getTeamBuildingInfo().getTeamBuildingName()).isEqualTo("넥스터즈 팀빌딩이에요"); + assertThat(teamBuildingResponse.getTeamInfoList().get(0).getTeamName()).isEqualTo("team1"); + assertThat(teamBuildingResponse.getTeamInfoList().get(0).getPmPosition()).isEqualTo(Position.FRONT_END); + } + + + @Transactional + @Test + @DisplayName("조정 단계에서 팀1 -> 팀2로 옮겨졌을 때") + void adjustUserToDifferentTeam() { + final TeamBuilding teamBuilding = teamBuildingRepository.save(FixtureTeamBuilding.teamBuilding(RoundStatus.ADJUSTED_ROUND)); + final Team team1 = teamBuilding.getTeams().get(0); + final Team team2 = teamBuilding.getTeams().get(1); + + final User user = userRepository.save(User.builder() + .name("넥터사람") + .position(Position.BACK_END) + .choices(List.of("1", "2", "3", "4")) + .team(team1) + .build()); + + final UserInfo adjustedUser = sut.adjustUser(teamBuilding.getUuid(), user.getUuid(), team2.getUuid()); + assertThat(adjustedUser.getJoinedTeamUuid()).isEqualTo(team2.getUuid()); + assertThat(adjustedUser.getSelectedRound()).isEqualTo(RoundStatus.ADJUSTED_ROUND); + } + + @Transactional + @Test + @DisplayName("조정 단계에서 할당됭 팀을 해제했을 때") + void adjustUserToNotAssigned() { + final TeamBuilding teamBuilding = teamBuildingRepository.save(FixtureTeamBuilding.teamBuilding(RoundStatus.ADJUSTED_ROUND)); + final Team team1 = teamBuilding.getTeams().get(0); + + final User user = userRepository.save(User.builder() + .name("넥터사람") + .position(Position.BACK_END) + .choices(List.of("1", "2", "3", "4")) + .team(team1) + .build()); + + final UserInfo adjustedUser = sut.adjustUser(teamBuilding.getUuid(), user.getUuid(), null); + assertThat(adjustedUser.getJoinedTeamUuid()).isNull(); + assertThat(adjustedUser.getSelectedRound()).isNull(); + } + + @Test + void deleteTeamBuildingUser() { + final TeamBuilding teamBuilding = teamBuildingRepository.save(FixtureTeamBuilding.teamBuilding(RoundStatus.START)); + + final User user = userRepository.save(User.builder() + .name("넥터사람") + .position(Position.BACK_END) + .choices(List.of("1", "2", "3", "4")) + .teamBuildingUuid(teamBuilding.getUuid()) + .build()); + + sut.deleteTeamBuildingUser(teamBuilding.getUuid(), user.getUuid()); + + assertThat(userRepository.findByUuid(user.getUuid())).isEmpty(); + } + + @Test + @Transactional + void finishTeamBuilding() { + final TeamBuilding teamBuilding = teamBuildingRepository.save(FixtureTeamBuilding.teamBuilding(RoundStatus.ADJUSTED_ROUND)); + + sut.finishTeamBuilding(teamBuilding.getUuid()); + + assertThat(teamBuilding.getRoundStatus()).isEqualTo(RoundStatus.COMPLETE); + } +} diff --git a/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreServiceTest.java b/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreServiceTest.java new file mode 100644 index 0000000..33e8863 --- /dev/null +++ b/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreServiceTest.java @@ -0,0 +1,116 @@ +package com.nexters.moyeomoyeo.team_building.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.nexters.moyeomoyeo.MoyeoMoyeoTest; +import com.nexters.moyeomoyeo.team_building.controller.dto.request.UserPickRequest; +import com.nexters.moyeomoyeo.team_building.controller.dto.response.UserPickResponse; +import com.nexters.moyeomoyeo.team_building.domain.constant.Position; +import com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus; +import com.nexters.moyeomoyeo.team_building.domain.entity.Team; +import com.nexters.moyeomoyeo.team_building.domain.entity.TeamBuilding; +import com.nexters.moyeomoyeo.team_building.domain.entity.User; +import com.nexters.moyeomoyeo.team_building.domain.repository.TeamBuildingRepository; +import com.nexters.moyeomoyeo.team_building.domain.repository.UserRepository; +import com.nexters.moyeomoyeo.team_building.fixture.FixtureTeamBuilding; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@MoyeoMoyeoTest +class TeamBuildingCoreServiceTest { + + @Autowired + private TeamBuildingCoreService sut; + + @Autowired + private TeamBuildingRepository teamBuildingRepository; + + @Autowired + private UserRepository userRepository; + + @Transactional + @Test + @DisplayName("첫번째 라운드에서 한 팀이 유저 선택 완료후 다음라운드로 넘어가는지") + void pickUserOne() { + final TeamBuilding teamBuilding = teamBuildingRepository.save(FixtureTeamBuilding.teamBuilding(RoundStatus.FIRST_ROUND)); + + final List teams = teamBuilding.getTeams(); + final Team sutTeam = teams.get(0); + final User user = userRepository.save(User.builder() + .name("넥터사람") + .position(Position.BACK_END) + .choices(List.of(sutTeam.getUuid(), teams.get(1).getUuid(), teams.get(2).getUuid(), teams.get(3).getUuid())) + .teamBuildingUuid(teamBuilding.getUuid()) + .build()); + + final UserPickResponse userPickResponse = sut.pickUsers(teamBuilding.getUuid(), sutTeam.getUuid(), UserPickRequest.builder() + .userUuids(List.of(user.getUuid())) + .build()); + + assertThat(userPickResponse.getUserInfoList().get(0).getUserName()).isEqualTo("넥터사람"); + assertThat(userPickResponse.getUserInfoList().get(0).getPosition()).isEqualTo(Position.BACK_END); + assertThat(userPickResponse.getUserInfoList().get(0).getSelectedRound()).isEqualTo(RoundStatus.FIRST_ROUND); + assertThat(sutTeam.getRoundStatus()).isEqualTo(RoundStatus.SECOND_ROUND); + } + + @Transactional + @Test + @DisplayName("첫번째 라운드에서 한 팀이 유저 선택을 아무도 하지 않은 후 다음라운드로 넘어가는지") + void pickUserNoOne() { + final TeamBuilding teamBuilding = teamBuildingRepository.save(FixtureTeamBuilding.teamBuilding(RoundStatus.FIRST_ROUND)); + + final List teams = teamBuilding.getTeams(); + final Team sutTeam = teams.get(0); + + final UserPickResponse userPickResponse = sut.pickUsers(teamBuilding.getUuid(), sutTeam.getUuid(), UserPickRequest.builder() + .userUuids(List.of()) + .build()); + + assertThat(userPickResponse.getUserInfoList()).isEmpty(); + assertThat(sutTeam.getRoundStatus()).isEqualTo(RoundStatus.SECOND_ROUND); + } + + @Transactional + @Test + @DisplayName("첫번째 라운드에서 모든 팀이 유저 선택 완료 후 팀빌딩이 다음라운드로 넘어가는지") + void pickUserALL() { + final TeamBuilding teamBuilding = teamBuildingRepository.save(FixtureTeamBuilding.teamBuilding(RoundStatus.FIRST_ROUND)); + + final List teams = teamBuilding.getTeams(); + + final User user1 = userRepository.save(User.builder() + .name("넥터사람1") + .position(Position.BACK_END) + .choices(List.of(teams.get(0).getUuid(), teams.get(1).getUuid(), teams.get(2).getUuid(), teams.get(3).getUuid())) + .teamBuildingUuid(teamBuilding.getUuid()) + .build()); + + final User user2 = userRepository.save(User.builder() + .name("넥터사람2") + .position(Position.FRONT_END) + .choices(List.of(teams.get(0).getUuid(), teams.get(1).getUuid(), teams.get(2).getUuid(), teams.get(3).getUuid())) + .teamBuildingUuid(teamBuilding.getUuid()) + .build()); + + sut.pickUsers(teamBuilding.getUuid(), teams.get(0).getUuid(), UserPickRequest.builder() + .userUuids(List.of(user1.getUuid(), user2.getUuid())) + .build()); + + sut.pickUsers(teamBuilding.getUuid(), teams.get(1).getUuid(), UserPickRequest.builder() + .userUuids(List.of()) + .build()); + + sut.pickUsers(teamBuilding.getUuid(), teams.get(2).getUuid(), UserPickRequest.builder() + .userUuids(List.of()) + .build()); + + sut.pickUsers(teamBuilding.getUuid(), teams.get(3).getUuid(), UserPickRequest.builder() + .userUuids(List.of()) + .build()); + + assertThat(teamBuilding.getRoundStatus()).isEqualTo(RoundStatus.SECOND_ROUND); + } +} diff --git a/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingServiceTest.java b/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingServiceTest.java deleted file mode 100644 index bbd7e03..0000000 --- a/src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingServiceTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.nexters.moyeomoyeo.team_building.service; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.nexters.moyeomoyeo.MoyeoMoyeoTest; -import com.nexters.moyeomoyeo.team_building.controller.dto.request.TeamBuildingRequest; -import com.nexters.moyeomoyeo.team_building.controller.dto.request.TeamRequest; -import com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamBuildingResponse; -import com.nexters.moyeomoyeo.team_building.domain.constant.Position; -import com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -@MoyeoMoyeoTest -class TeamBuildingServiceTest { - - @Autowired - private TeamBuildingService teamBuildingService; - - @Autowired - private TeamBuildingAdminService adminService; - - - @Test - void createTeamBuilding() { - final var saveResponse = saveTeamBuildingWithTeams(); - final TeamBuildingResponse findResponse = teamBuildingService.findTeamBuildingAndTeams( - saveResponse.getTeamBuildingInfo().getTeamBuildingUrl()); - - // team building - assertEquals(saveResponse.getTeamBuildingInfo().getTeamBuildingUrl(), - findResponse.getTeamBuildingInfo().getTeamBuildingUrl()); - assertEquals(RoundStatus.FIRST_ROUND, findResponse.getTeamBuildingInfo().getRoundStatus()); - - //team - assertEquals(saveResponse.getTeamInfoList().get(0).getTeamName(), - findResponse.getTeamInfoList().get(0).getTeamName()); - assertEquals(saveResponse.getTeamInfoList().get(1).getTeamName(), - findResponse.getTeamInfoList().get(1).getTeamName()); - } - - private TeamBuildingResponse saveTeamBuildingWithTeams() { - return adminService.createTeamBuilding(TeamBuildingRequest.builder() - .name("team-Building") - .teams(List.of( - TeamRequest.builder() - .name("team1") - .pmName("pm1") - .pmPosition(Position.FRONT_END) - .build(), - TeamRequest.builder() - .name("team2") - .pmName("pm2") - .pmPosition(Position.BACK_END) - .build())) - .build()); - } -} diff --git a/src/test/java/com/nexters/moyeomoyeo/team_building/service/UserServiceTest.java b/src/test/java/com/nexters/moyeomoyeo/team_building/service/UserServiceTest.java new file mode 100644 index 0000000..8fe9f06 --- /dev/null +++ b/src/test/java/com/nexters/moyeomoyeo/team_building/service/UserServiceTest.java @@ -0,0 +1,49 @@ +package com.nexters.moyeomoyeo.team_building.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.*; + +import com.nexters.moyeomoyeo.MoyeoMoyeoTest; +import com.nexters.moyeomoyeo.common.constant.ExceptionInfo; +import com.nexters.moyeomoyeo.common.exception.vo.CustomException; +import com.nexters.moyeomoyeo.team_building.controller.dto.request.UserRequest; +import com.nexters.moyeomoyeo.team_building.controller.dto.response.UserInfo; +import com.nexters.moyeomoyeo.team_building.domain.constant.Position; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +@MoyeoMoyeoTest +class UserServiceTest { + + @Autowired + private UserService sut; + + @Test + void createUser() { + final UserInfo userInfo = sut.createUser("team-building-uuid", UserRequest.builder() + .name("넥터사람") + .position(Position.BACK_END) + .choices(List.of("1", "2", "3", "4")) + .build()); + + assertThat(userInfo.getUserName()).isEqualTo("넥터사람"); + assertThat(userInfo.getPosition()).isEqualTo(Position.BACK_END); + assertThat(userInfo.getChoices().get(0)).isEqualTo("1"); + } + + @Test + void deleteUser() { + final UserInfo createdUser = sut.createUser("team-building-uuid", UserRequest.builder() + .name("넥터사람") + .position(Position.BACK_END) + .choices(List.of("1", "2", "3", "4")) + .build()); + + sut.deleteUser("team-building-uuid", createdUser.getUuid()); + + assertThatThrownBy(() -> sut.findByUuid(createdUser.getUuid())) + .isInstanceOf(CustomException.class).hasMessage(ExceptionInfo.INVALID_USER_UUID.getMessage()); + } +}