Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum PetPlantExceptionMessage implements ExceptionMessage {
NOT_FOUND_DAILY_RECORD("해당 날짜의 기록이 존재하지 않습니다.", "404"),
ALREADY_EXISTS_DAILY_RECORD("이미 작성한 오늘의 기록이 존재합니다", "409"),

INVALID_DATE_ACCESS("해당 날짜에만 접근 가능합니다.", "400");
INVALID_DATE_ACCESS("해당 날짜에 미리 접근할 수 없습니다.", "400");

private final String message;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public CreateDailyRecordResponseDto createDailyRecord(
}

//3
if (!Objects.equals(nowDate.get(), requestDto.today())) {
//현재 시간 < 요청으로 들어온 시간
if (nowDate.get().isBefore(requestDto.today())) {
throw new GreeningGlobalException(PetPlantExceptionMessage.INVALID_DATE_ACCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public WateringPlantResponseDto wateringPlant(
PetPlantExceptionMessage.BAD_REQUEST_PET_PLANT_WRITER);
}

if (!Objects.equals(nowDate.get(), today)) {
if (nowDate.get().isBefore(today)) {
throw new GreeningGlobalException(PetPlantExceptionMessage.INVALID_DATE_ACCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TestCase1 {

LocalDate now = LocalDate.of(2025, 7, 3);

LocalDate future = LocalDate.of(2025, 7, 5);
LocalDate past = LocalDate.of(2025, 7, 2);

String title = "제목";

Expand Down Expand Up @@ -138,10 +138,10 @@ void createDailyRecord2() throws Exception {
}

@Test
@DisplayName("오늘이 아닌 날짜에 대해 오늘의 기록을 작성할 수 없다.")
@DisplayName("오늘보다 이후 날짜에 대해 오늘의 기록을 작성할 수 없다.")
void createDailyRecord3() throws Exception {
//given
given(nowDate.get()).willReturn(future);
given(nowDate.get()).willReturn(past);

//when
ResultActions perform = mockMvc.perform(
Expand Down Expand Up @@ -213,4 +213,4 @@ void getDailyRecord1() throws Exception {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ void createDailyRecord2() {
}

@Test
@DisplayName("오늘이 아닌 날짜에 대해 오늘의 기록을 작성할 수 없다.")
@DisplayName("오늘보다 이후 날짜에 대해 오늘의 기록을 작성할 수 없다.")
void createDailyRecord3() {
//given
List<DailyRecordContentDto> contents = List.of(
new DailyRecordContentDto("TEXT", content));

given(now.get()).willReturn(nowDate);

//when
ThrowingCallable throwingCallable = () -> dailyRecordCommandService.createDailyRecord(
userId, petPlant.getId(),
Expand All @@ -141,4 +143,4 @@ void createDailyRecord3() {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TestCase1 {
private final String type = "민들레";

private final LocalDate nowDate = LocalDate.of(2025,7,3);
private final LocalDate future = LocalDate.of(2030,8,16);
private final LocalDate future = LocalDate.of(2026,8,16);

private PetPlant petPlant;

Expand Down Expand Up @@ -87,7 +87,7 @@ void wateringPlantTest() {
userId, petPlant.getId(), nowDate);

//then
assertThat(1L).isEqualTo(result.wateringId());
assertThat(result.wateringId()).isEqualTo(1L);
verify(wateringRepository, times(1)).save(any(Watering.class));
}

Expand All @@ -105,21 +105,19 @@ void wateringPlantTest2() {
}

@Test
@DisplayName("오늘이 아닌 날짜의 물을 줄 수 없다.")
@DisplayName("오늘보다 이후 날짜의 물을 줄 수 없다.")
void wateringPlantTest3() {
//given
given(now.get()).willReturn(future);
given(now.get()).willReturn(nowDate);

//when
ThrowingCallable throwingCallable = () -> wateringService.wateringPlant(
userId, petPlant.getId(), nowDate);
userId, petPlant.getId(), future);

//then
assertThatThrownBy(throwingCallable)
.isInstanceOf(GreeningGlobalException.class)
.hasMessage(PetPlantExceptionMessage.INVALID_DATE_ACCESS.getMessage());
}
}


}
}
Loading