Skip to content

Commit

Permalink
refactor(Meeting): lastTime 필드의 의미가 달라지면서 생성 로직 수정
Browse files Browse the repository at this point in the history
Timeslot이 아닌 LocalTime으로 받고 이를 변환한다.
  • Loading branch information
ehBeak committed Jul 24, 2024
1 parent 5c4b4fe commit eac007a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.LocalTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down Expand Up @@ -50,6 +51,10 @@ public Meeting(String name, String uuid, Timeslot firstTimeslot, Timeslot lastTi
this.lastTimeslot = lastTimeslot;
}

public Meeting(String name, String uuid, LocalTime firstTime, LocalTime lastTime) {
this(name, uuid, Timeslot.from(firstTime), Timeslot.from(lastTime.minusMinutes(30)));
}

private void validateTimeRange(Timeslot firstTimeslot, Timeslot lastTimeslot) {
if (lastTimeslot == firstTimeslot) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.woowacourse.momo.domain.meeting.MeetingRepository;
import com.woowacourse.momo.domain.schedule.Schedule;
import com.woowacourse.momo.domain.schedule.ScheduleRepository;
import com.woowacourse.momo.domain.timeslot.Timeslot;
import com.woowacourse.momo.exception.MomoException;
import com.woowacourse.momo.exception.code.MeetingErrorCode;
import com.woowacourse.momo.service.meeting.dto.MeetingCreateRequest;
Expand Down Expand Up @@ -65,8 +64,8 @@ public String create(MeetingCreateRequest request) {
Meeting meeting = new Meeting(
request.meetingName(),
uuid,
Timeslot.from(request.meetingStartTime()),
Timeslot.from(request.meetingEndTime())
request.meetingStartTime(),
request.meetingEndTime()
);
Meeting savedMeeting = meetingRepository.save(meeting);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,67 @@
package com.woowacourse.momo.domain.meeting;

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

import com.woowacourse.momo.domain.timeslot.Timeslot;
import com.woowacourse.momo.exception.MomoException;
import com.woowacourse.momo.exception.code.MeetingErrorCode;
import java.time.LocalTime;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class MeetingTest {

@DisplayName("약속 시작 시간이 약속 마지막 시간보다 늦은 시간이면 예외가 발생한다.")
@DisplayName("약속 시작 시간이 끝 시간과 같으면 예외가 발생한다.")
@Test
void throwExceptionWhenInvalidTimeRange() {
assertThatThrownBy(() -> new Meeting("momo", "momo", Timeslot.TIME_1500, Timeslot.TIME_0600))
void throwExceptionWhenEqualStartTimeIsEqualEndTime() {
// given
LocalTime startTime = LocalTime.of(15, 0);
LocalTime endTime = LocalTime.of(15, 0);

// when then
assertThatThrownBy(() -> new Meeting("momo", "momo", startTime, endTime))
.isInstanceOf(MomoException.class)
.hasMessage(MeetingErrorCode.INVALID_TIME_RANGE.message());
}

@DisplayName("약속 시작 시간이 끝 시간보다 늦으면 예외가 발생한다.")
@Test
void throwExceptionWhenStartTimeIsAfterEndTime() {
// given
LocalTime startTime = LocalTime.of(15, 0);
LocalTime endTime = LocalTime.of(10, 0);

// when then
assertThatThrownBy(() -> new Meeting("momo", "momo", startTime, endTime))
.isInstanceOf(MomoException.class)
.hasMessage(MeetingErrorCode.INVALID_TIME_RANGE.message());
}

@DisplayName("약속 시작 시간이 마지막 시간과 같으면 예외가 발생하지 않는다.")
@DisplayName("약속 시작 시간이 끝 시간보다 빠르면 예외가 발생하지 않는다.")
@Test
void doesNotThrowExceptionStartAndEndTimeSame() {
assertThatCode(() -> new Meeting("momo", "momo", Timeslot.TIME_1500, Timeslot.TIME_1500))
// given
LocalTime startTime = LocalTime.of(10, 0);
LocalTime endTime = LocalTime.of(15, 0);

// when then
assertThatCode(() -> new Meeting("momo", "momo", startTime, endTime))
.doesNotThrowAnyException();
}

@DisplayName("자정 시간을 23시 30분 타임슬롯으로 변경한다")
@Test
void canConvertMidnight() {
// given
LocalTime startTime = LocalTime.of(10, 0);
LocalTime endTime = LocalTime.of(0, 0);

// when
Meeting meeting = new Meeting("momo", "momo", startTime, endTime);

// when then
assertThat(meeting.getLastTimeslot()).isEqualTo(Timeslot.TIME_2330);
}
}

0 comments on commit eac007a

Please sign in to comment.