Skip to content

Commit

Permalink
[PDS-171] test:회의실 목록조회 실패 case 테스트 코드 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
leeseunghakhello committed Nov 24, 2023
1 parent bf91579 commit b8f576b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,70 @@ void searchOffice() throws Exception {
.andExpect(status().isOk());
}

@DisplayName("회의실 목록 조회 실패 case1->날짜나 시간이 입력되지 않은 경우")
@Test
@WithMockUser
void searchOffice_whenDateOrTimeNotProvided_thenThrowsException() throws Exception {
// given
LocalDate date = LocalDate.of(2023, 11, 30);
String facilityName = "빔 프로젝터";
Pageable pageable = PageRequest.of(0, 10);

// when-then
mockMvc.perform(get("/offices")
.param("date", date.toString())
.param("facilityName", facilityName)
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest());
}
@DisplayName("회의실 목록 조회 실패 case2->과거의 날짜와 시간을 예약으로 시도할 경우")
@Test
@WithMockUser
void searchOffice_whenPastDateAndTime_thenThrowsException() throws Exception {
// given
LocalDate date = LocalDate.now().minusDays(1); //과거날짜 주입
LocalTime startTime = LocalTime.of(12, 0);
LocalTime endTime = LocalTime.of(13, 0);
String facilityName = "빔 프로젝터";
Pageable pageable = PageRequest.of(0, 10);

// when-then
mockMvc.perform(get("/offices")
.param("date", date.toString())
.param("startTime", startTime.toString())
.param("endTime", endTime.toString())
.param("facilityName", facilityName)
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest());
}

@DisplayName("회의실 목록 조회 실패 case3->시작 시간이 종료 시간보다 늦거나 같은 경우")
@Test
@WithMockUser
void searchOffice_whenStartTimeAfterEndTime_thenThrowsException() throws Exception {
// given
LocalDate date = LocalDate.of(2023, 11, 30);
LocalTime startTime = LocalTime.of(13, 0);
LocalTime endTime = LocalTime.of(12, 0); // 시작 시간이 종료 시간보다 늦은 시간 주입
String facilityName = "빔 프로젝터";
Pageable pageable = PageRequest.of(0, 10);

// when-then
mockMvc.perform(get("/offices")
.param("date", date.toString())
.param("startTime", startTime.toString())
.param("endTime", endTime.toString())
.param("facilityName", facilityName)
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest());
}




@DisplayName("회의실 개별 조회")
@Test
void getOffice() throws Exception{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public class OfficeServiceTest extends IntegrationTestSupport {
@Autowired private AffiliationRepository affiliationRepository;
@Autowired private DepartmentRepository departmentRepository;

@AfterEach
void tearDown(){
// 참조하는 엔티티 먼저 삭제
officeBookingRepository.deleteAllInBatch();
officeFacilityRepository.deleteAllInBatch();
// 참조되는 엔티티 삭제
officeRepository.deleteAllInBatch();
facilityRepository.deleteAllInBatch();

}
// @AfterEach
// void tearDown(){
// // 참조하는 엔티티 먼저 삭제
// officeBookingRepository.deleteAllInBatch();
// officeFacilityRepository.deleteAllInBatch();
// // 참조되는 엔티티 삭제
// officeRepository.deleteAllInBatch();
// facilityRepository.deleteAllInBatch();
//
// }

@Test
@DisplayName("회의실 목록 조회 테스트")
Expand Down

0 comments on commit b8f576b

Please sign in to comment.