diff --git a/src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java b/src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java index dfa0d6c..16920ef 100644 --- a/src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java +++ b/src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java @@ -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; diff --git a/src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java b/src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java index 4bd294a..95b9002 100644 --- a/src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java +++ b/src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java @@ -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); } diff --git a/src/main/java/swyp/team5/greening/petPlant/service/WateringService.java b/src/main/java/swyp/team5/greening/petPlant/service/WateringService.java index 8cddffc..951b396 100644 --- a/src/main/java/swyp/team5/greening/petPlant/service/WateringService.java +++ b/src/main/java/swyp/team5/greening/petPlant/service/WateringService.java @@ -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); } diff --git a/src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java b/src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java index 18fbe7c..f255a3c 100644 --- a/src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java +++ b/src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java @@ -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 = "제목"; @@ -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( @@ -213,4 +213,4 @@ void getDailyRecord1() throws Exception { } } -} \ No newline at end of file +} diff --git a/src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java b/src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java index 0e18f4e..0d98d55 100644 --- a/src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java +++ b/src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java @@ -122,12 +122,14 @@ void createDailyRecord2() { } @Test - @DisplayName("오늘이 아닌 날짜에 대해 오늘의 기록을 작성할 수 없다.") + @DisplayName("오늘보다 이후 날짜에 대해 오늘의 기록을 작성할 수 없다.") void createDailyRecord3() { //given List contents = List.of( new DailyRecordContentDto("TEXT", content)); + given(now.get()).willReturn(nowDate); + //when ThrowingCallable throwingCallable = () -> dailyRecordCommandService.createDailyRecord( userId, petPlant.getId(), @@ -141,4 +143,4 @@ void createDailyRecord3() { } } -} \ No newline at end of file +} diff --git a/src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java b/src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java index 3f330db..3e735e1 100644 --- a/src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java +++ b/src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java @@ -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; @@ -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)); } @@ -105,14 +105,14 @@ 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) @@ -120,6 +120,4 @@ void wateringPlantTest3() { .hasMessage(PetPlantExceptionMessage.INVALID_DATE_ACCESS.getMessage()); } } - - -} \ No newline at end of file +}