Skip to content

Commit

Permalink
refactor(tab) : cmdTab 테스트코드 수정
Browse files Browse the repository at this point in the history
db에 데이터 없어도 insert 후 동작하도록 수정
  • Loading branch information
Sosohy committed Jun 25, 2024
1 parent 3b47ea2 commit b452d78
Showing 1 changed file with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import org.triumers.kmsback.common.exception.NotLoginException;
import org.triumers.kmsback.tab.command.Application.dto.CmdJoinEmployeeDTO;
import org.triumers.kmsback.tab.command.Application.dto.CmdTabDTO;
import org.triumers.kmsback.tab.command.Application.dto.CmdTabRelationDTO;
import org.triumers.kmsback.tab.command.domain.repository.CmdJoinEmployeeRepository;
import org.triumers.kmsback.user.command.Application.service.AuthService;
import org.triumers.kmsback.user.command.domain.aggregate.entity.Employee;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -19,50 +22,61 @@ class CmdTabServiceTests {

private final CmdTabService cmdTabService;
private final CmdJoinEmployeeRepository cmdJoinEmployeeRepository;

private final int EMPLOYEE_ID = 1;
private final int TAB_RELATION_ID = 999;
private final AuthService authService;

@Autowired
CmdTabServiceTests(CmdTabService cmdTabService, CmdJoinEmployeeRepository cmdJoinEmployeeRepository) {
CmdTabServiceTests(CmdTabService cmdTabService, CmdJoinEmployeeRepository cmdJoinEmployeeRepository, AuthService authService) {
this.cmdTabService = cmdTabService;
this.cmdJoinEmployeeRepository = cmdJoinEmployeeRepository;
this.authService = authService;
}

// @Test
// @DisplayName("탭 참여자 등록")
// void addEmployeeTab(){
//
// CmdJoinEmployeeDTO employee = new CmdJoinEmployeeDTO(false, EMPLOYEE_ID, TAB_RELATION_ID);
//
// CmdJoinEmployeeDTO savedEmployee = cmdTabService.addEmployeeTab(employee);
//
// assertThat(savedEmployee.getId()).isNotNull();
// }
//
// @Test
// @DisplayName("탭 참여자 삭제")
// void deleteEmployeeTab(){
//
// CmdJoinEmployeeDTO employee = new CmdJoinEmployeeDTO(false, EMPLOYEE_ID, TAB_RELATION_ID);
// cmdTabService.addEmployeeTab(employee);
//
// CmdJoinEmployeeDTO deletedEmployee = cmdTabService.deleteEmployeeTab(employee);
//
// assertThat(cmdJoinEmployeeRepository.findById(deletedEmployee.getId())).isEmpty();
// }
@Test
@DisplayName("탭 참여자 등록")
void addEmployeeTab() throws NotLoginException {

Employee employee = authService.whoAmI();
CmdTabRelationDTO tab = createTestTab();

CmdJoinEmployeeDTO joinEmployee = new CmdJoinEmployeeDTO(false, employee.getId(), tab.getId());

CmdJoinEmployeeDTO savedEmployee = cmdTabService.addEmployeeTab(joinEmployee);

assertThat(savedEmployee.getId()).isNotNull();
}

@Test
@DisplayName("탭 추가")
void registTab(){
boolean isPublic = false;
CmdTabDTO top = new CmdTabDTO("top");
CmdTabDTO bottom = new CmdTabDTO("bottom");
@DisplayName("탭 참여자 삭제")
void deleteEmployeeTab() throws NotLoginException {

Employee employee = authService.whoAmI();
CmdTabRelationDTO tab = createTestTab();

CmdJoinEmployeeDTO joinEmployee = new CmdJoinEmployeeDTO(false, employee.getId(), tab.getId());
cmdTabService.addEmployeeTab(joinEmployee);

CmdTabRelationDTO tabRelation = new CmdTabRelationDTO(isPublic, bottom, top);
CmdJoinEmployeeDTO deletedEmployee = cmdTabService.deleteEmployeeTab(joinEmployee);

CmdTabRelationDTO registTab = cmdTabService.registTab(tabRelation, EMPLOYEE_ID);
assertThat(cmdJoinEmployeeRepository.findById(deletedEmployee.getId())).isEmpty();
}

@Test
@DisplayName("탭 추가")
void registTab() throws NotLoginException {

CmdTabRelationDTO registTab = createTestTab();

assertThat(registTab.getId()).isNotNull();
}

private CmdTabRelationDTO createTestTab() throws NotLoginException {

CmdTabDTO top = new CmdTabDTO("testTop");
CmdTabDTO bottom = new CmdTabDTO("testBottom");
CmdTabRelationDTO tabRelation = new CmdTabRelationDTO(false, bottom, top);

Employee employee = authService.whoAmI();

return cmdTabService.registTab(tabRelation, employee.getId());
}
}

0 comments on commit b452d78

Please sign in to comment.