Skip to content

Commit

Permalink
✨ [Feature] 전체일정 추가 api 테스트코드 작성 #1052 (#1083)
Browse files Browse the repository at this point in the history
Co-authored-by: wonie <wonies@github.com>
  • Loading branch information
wonies and wonie authored Dec 27, 2024
1 parent 4fb7a09 commit c84ca7f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gg.calendar.api.user.schedule.publicschedule.controller;


import javax.validation.Valid;

import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public void createPublicSchedule(PublicScheduleCreateReqDto req, Long userId) {
if (!user.getIntraId().equals(req.getAuthor())) {
throw new CustomRuntimeException(ErrorCode.CALENDAR_AUTHOR_NOT_MATCH);
}
if (req.getStartTime().isAfter(req.getEndTime())) {
throw new CustomRuntimeException(ErrorCode.CALENDAR_BEFORE_DATE);
}
PublicSchedule publicSchedule = PublicScheduleCreateReqDto.toEntity(user.getIntraId(), req);
publicScheduleRepository.save(publicSchedule);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package gg.calendar.api.user.schedule.publicschedule;

import java.time.LocalDateTime;

import javax.persistence.EntityManager;

import org.springframework.stereotype.Component;

import gg.calendar.api.user.schedule.publicschedule.controller.request.PublicScheduleCreateReqDto;
import gg.data.BaseTimeEntity;
import gg.data.calendar.PublicSchedule;
import gg.data.calendar.type.DetailClassification;
import gg.data.calendar.type.EventTag;
import gg.data.calendar.type.ScheduleStatus;

import gg.repo.calendar.PublicScheduleRepository;
import gg.utils.TestDataUtils;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,18 +16,5 @@ public class PublicScheduleMockData {
private final PublicScheduleRepository publicScheduleRepository;
private final TestDataUtils testDataUtils;

public PublicSchedule createPublicSchedule(String author) {
return PublicSchedule.builder()
.classification(DetailClassification.EVENT)
.jobTag(null)
.techTag(null)
.title("Test Schedule")
.status(ScheduleStatus.ACTIVATE)
.author(author)
.content("Test Content")
.link("http://test.com")
.startTime(LocalDateTime.now())
.endTime(LocalDateTime.now().plusDays(1))
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,33 @@ void createPublicScheduleFail() throws Exception {
List<PublicSchedule> schedules = publicScheduleRepository.findByAuthor(user.getIntraId());
assertThat(schedules).isEmpty();
}

@Test
@DisplayName("공개일정- 기간이 잘못되었을 때/ 종료닐짜가 시작날짜보다 빠를때")
void createPublicScheduleFail2() throws Exception {
// given : reqDto를 생성
PublicScheduleCreateReqDto publicScheduleDto = PublicScheduleCreateReqDto.builder()
.classification(DetailClassification.EVENT)
.eventTag(EventTag.ETC)
.author(user.getIntraId())
.title("Test Schedule")
.content("Test Content")
.link("http://test.com")
.startTime(LocalDateTime.now())
.endTime(LocalDateTime.now().minusDays(1))
.build();
// when : reqDto로 요청
mockMvc.perform(post("/calendar/public").header("Authorization", "Bearer " + accssToken)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(publicScheduleDto)))
.andExpect(status().isBadRequest())
.andExpect(result -> {
status().isBadRequest(); // 처음에 errorcode로 잡았는데, status로 잡음
})
.andDo(print());
// then : 예외가 발생
List<PublicSchedule> schedules = publicScheduleRepository.findByAuthor(user.getIntraId());
assertThat(schedules).isEmpty();
}
}
}

This file was deleted.

1 change: 0 additions & 1 deletion gg-utils/src/main/java/gg/utils/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ public enum ErrorCode {
PUBLIC_SCHEDULE_NOT_FOUND(404, "CA102", "공유 일정을 찾을 수 없습니다."),
SCHEDULE_GROUP_NOT_FOUND(404, "CA103", "스캐줄 그룹을 찾을 수 없습니다.");


private final int status;
private final String errCode;
private String message;
Expand Down

0 comments on commit c84ca7f

Please sign in to comment.