Skip to content

Commit

Permalink
Merge pull request #101 from Triumers/feat/auth
Browse files Browse the repository at this point in the history
[Refactor] 테스트 계정 생성 개선
  • Loading branch information
kyulin-Kim authored Jun 20, 2024
2 parents 4ebd8dd + 203c1ca commit 72c043b
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions src/test/java/org/triumers/kmsback/common/LoggedInUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import org.triumers.kmsback.organization.command.Application.dto.CmdCenterDTO;
import org.triumers.kmsback.organization.command.Application.dto.CmdDepartmentDTO;
import org.triumers.kmsback.organization.command.Application.dto.CmdTeamDTO;
import org.triumers.kmsback.organization.command.Application.service.CmdCenterService;
import org.triumers.kmsback.organization.command.Application.service.CmdDepartmentService;
import org.triumers.kmsback.organization.command.Application.service.CmdTeamService;
import org.triumers.kmsback.user.command.Application.dto.CmdPositionDTO;
import org.triumers.kmsback.user.command.Application.dto.CmdRankDTO;
import org.triumers.kmsback.user.command.Application.dto.ManageUserDTO;
import org.triumers.kmsback.user.command.Application.service.CmdDutyService;
import org.triumers.kmsback.user.command.Application.service.ManagerService;
import org.triumers.kmsback.user.command.domain.repository.EmployeeRepository;
import org.triumers.kmsback.user.command.domain.service.CustomUserDetailsService;
Expand All @@ -27,11 +36,69 @@ public class LoggedInUser {
@Autowired
private EmployeeRepository employeeRepository;

@Autowired
private CmdCenterService cmdCenterService;

@Autowired
private CmdDepartmentService cmdDepartmentService;

@Autowired
private CmdTeamService cmdTeamService;

@Autowired
private CmdDutyService cmdDutyService;

// 테스트용 본부 생성
private int addCenterForTest() {
CmdCenterDTO centerDTO = new CmdCenterDTO();
centerDTO.setName("UniqueCenterNameForTest");
return cmdCenterService.addCenter(centerDTO);
}

// 테스트용 부서 생성
private int addDepartmentForTest() {
int centerId = addCenterForTest();
CmdDepartmentDTO departmentDTO = new CmdDepartmentDTO();
departmentDTO.setName("UniqDepartmentNameForTest");
departmentDTO.setCenterId(centerId);
return cmdDepartmentService.addDepartment(departmentDTO);
}

// 테스트용 팀 생성
private int addTeamForTest() {
int departmentId = addDepartmentForTest();
CmdTeamDTO teamDTO = new CmdTeamDTO();
teamDTO.setName("UniqTeamNameForTest");
teamDTO.setDepartmentId(departmentId);

return cmdTeamService.addTeam(teamDTO);
}

// 테스트용 직책 생성
private int addPositionForTest() {
CmdPositionDTO positionDTO = new CmdPositionDTO();
positionDTO.setName("UniqPositionNameForTest");

return cmdDutyService.addPosition(positionDTO);
}

// 테스트용 직급 생성
private int addRankForTest() {
CmdRankDTO rankDTO = new CmdRankDTO();
rankDTO.setName("UniqRankNameForTest");

return cmdDutyService.addRank(rankDTO);
}

// 테스트용 계정 DTO 생성
private ManageUserDTO createRightAuthDTO() {
int teamId = addTeamForTest();
int positionId = addPositionForTest();
int rankId = addRankForTest();

return new ManageUserDTO(RIGHT_FORMAT_EMAIL, RIGHT_FORMAT_PASSWORD, RIGHT_FORMAT_NAME, null,
RIGHT_FORMAT_USER_ROLE, null, null, RIGHT_PHONE_NUMBER, 1, 1,
1);
RIGHT_FORMAT_USER_ROLE, null, null, RIGHT_PHONE_NUMBER, teamId, positionId,
rankId);
}

// 테스트용 관리자 계정 DTO 생성
Expand Down

0 comments on commit 72c043b

Please sign in to comment.