-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
박다예/NSC스튜디오/NE
committed
Jul 4, 2024
1 parent
4bbe242
commit df87130
Showing
11 changed files
with
346 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/test/java/com/nexters/moyeomoyeo/team_building/fixture/FixtureTeamBuilding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingAdminServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
src/test/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Team> 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<Team> 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<Team> 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); | ||
} | ||
} |
Oops, something went wrong.