Skip to content

Commit

Permalink
Merge pull request #104 from Cafegory/feature-103
Browse files Browse the repository at this point in the history
[BUILD SUCCESS] fix: 카공 시간 수정시 카페 영업시간 이후로 수정이 되는 오류 해결
  • Loading branch information
donghyun0304 authored May 16, 2024
2 parents 8460ab8 + daedbe1 commit 78d8bba
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public void updateStudyOnce(long requestedMemberId, long studyOnceId, StudyOnceU
studyOnce.changeName(request.getName());
}
if (request.getStartDateTime() != null && request.getEndDateTime() != null) {
Cafe cafe = studyOnce.getCafe();
validateBetweenBusinessHour(request.getStartDateTime().toLocalTime(),
request.getEndDateTime().toLocalTime(), cafe.findBusinessHour(now.getDayOfWeek()));
studyOnce.changeStudyOnceTime(request.getStartDateTime(), request.getEndDateTime());
}
if (request.getOpenChatUrl() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,84 @@ void update_studyOnce_by_invalid_member_then_exception() {
.hasMessage(STUDY_ONCE_LEADER_PERMISSION_DENIED.getErrorMessage());
}

@ParameterizedTest
@MethodSource("provideStartAndEndDateTime3")
@DisplayName("카공 시작시간과 종료시간 수정시 카페 영업시간 이후로 수정할 경우 예외가 터진다.")
void update_studyOnce_between_not_businessHours_then_exception(LocalDateTime start, LocalDateTime end) {
List<BusinessHour> businessHours = makeBusinessHourWith7daysFrom9To21();
long cafeId = cafePersistHelper.persistCafeWithBusinessHour(businessHours).getId();
long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId();
StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(LocalDateTime.of(2999, 1, 1, 9, 0),
LocalDateTime.of(2999, 1, 1, 10, 0),
cafeId);
StudyOnceCreateResponse studyOnceCreateResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest,
LocalDate.now());

StudyOnceUpdateRequest studyOnceUpdateRequest = new StudyOnceUpdateRequest(cafeId, null, start, end, 5, true,
null);

assertThatThrownBy(
() -> studyOnceService.updateStudyOnce(leaderId, studyOnceCreateResponse.getStudyOnceId(),
studyOnceUpdateRequest, LocalDateTime.of(2999, 1, 1, 8, 0)))
.isInstanceOf(CafegoryException.class)
.hasMessage(STUDY_ONCE_CREATE_BETWEEN_CAFE_BUSINESS_HOURS.getErrorMessage());
}

static Stream<Arguments> provideStartAndEndDateTime3() {
return Stream.of(
Arguments.of(
LocalDateTime.of(2999, 1, 1, 8, 59, 59, 999_999_999),
LocalDateTime.of(2999, 1, 1, 10, 0)
),
Arguments.of(
LocalDateTime.of(2999, 1, 1, 8, 0),
LocalDateTime.of(2999, 1, 1, 9, 0, 0, 1)
),
Arguments.of(
LocalDateTime.of(2999, 1, 1, 20, 0),
LocalDateTime.of(2999, 1, 1, 21, 0, 0, 1)
),
Arguments.of(
LocalDateTime.of(2999, 1, 1, 20, 59, 59, 999_999_999),
LocalDateTime.of(2999, 1, 1, 22, 0)
)
);
}

@ParameterizedTest()
@MethodSource("provideStartAndEndDateTime4")
@DisplayName("카공 시작시간과 종료시간 수정시 카페 영업시간 사이로 선택 할 경우 수정된다.")
void update_studyOnce_between__businessHours(LocalDateTime start, LocalDateTime end) {
List<BusinessHour> businessHours = makeBusinessHourWith7daysFrom9To21();
long cafeId = cafePersistHelper.persistCafeWithBusinessHour(businessHours).getId();
long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId();
StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(LocalDateTime.of(2999, 1, 1, 9, 0),
LocalDateTime.of(2999, 1, 1, 10, 0),
cafeId);
StudyOnceCreateResponse studyOnceCreateResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest,
LocalDate.now());

StudyOnceUpdateRequest studyOnceUpdateRequest = new StudyOnceUpdateRequest(cafeId, null, start, end, 5, true,
null);

assertDoesNotThrow(
() -> studyOnceService.updateStudyOnce(leaderId, studyOnceCreateResponse.getStudyOnceId(),
studyOnceUpdateRequest, LocalDateTime.of(2999, 1, 1, 8, 0)));
}

static Stream<Arguments> provideStartAndEndDateTime4() {
return Stream.of(
Arguments.of(
LocalDateTime.of(2999, 1, 1, 9, 0),
LocalDateTime.of(2999, 1, 1, 10, 0)
),
Arguments.of(
LocalDateTime.of(2999, 1, 1, 20, 0),
LocalDateTime.of(2999, 1, 1, 21, 0)
)
);
}

@Test
@DisplayName("참여자가 존재하는 경우, 카공 수정")
void updateStudyOncePartially() {
Expand Down

0 comments on commit 78d8bba

Please sign in to comment.