Skip to content

Commit

Permalink
M3-212 Feat : 즐겨찾기 삭제 service test작성
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdals802 committed Aug 8, 2024
1 parent e60ed35 commit 29bbcfa
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/test/java/com/m3pro/groundflip/service/MyPlaceServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,48 @@ void getMyPlaceErrorTest() {
//When
assertEquals(ErrorCode.PLACE_NOT_FOUND, thrown.getErrorCode());
}

@Test
@DisplayName("[deleteMyPlace] 즐겨찾기 삭제 동작 테스트")
void deleteMyPlaceTest() {
//Given
Long userId = 1L;

myPlaceRequest = MyPlaceRequest.builder()
.userId(userId)
.placeName(Place.HOME)
.build();

List<MyPlace> myPlaceList = Arrays.asList(
MyPlace.builder().placeName(Place.HOME).user(user).build(),
MyPlace.builder().placeName(Place.HOME).user(user).build()
);

//when(myPlaceRepository.findByUserIdAndPlaceName(userId, Place.HOME)).thenReturn(myPlaceList);

myPlaceRepository.deleteAll(myPlaceList);

verify(myPlaceRepository, times(1)).deleteAll(myPlaceList);

}

@Test
@DisplayName("[deleteMyPlace] 즐겨찾기 장소가 존재하지 않을 때 에러가 발생하는지")
void deleteMyPlace_NotFound() {
// Given
Long userId = 1L;
Place placeName = Place.HOME;
MyPlaceRequest myPlaceRequest = MyPlaceRequest.builder()
.userId(userId)
.placeName(placeName)
.build();

// When

AppException thrown = assertThrows(AppException.class, () -> {
myPlaceService.deleteMyPlace(myPlaceRequest);
});

assertEquals(ErrorCode.PLACE_NOT_FOUND, thrown.getErrorCode());
}
}

0 comments on commit 29bbcfa

Please sign in to comment.