diff --git a/src/main/java/com/example/sinitto/guard/service/GuardService.java b/src/main/java/com/example/sinitto/guard/service/GuardService.java index e620d930..b08fab92 100644 --- a/src/main/java/com/example/sinitto/guard/service/GuardService.java +++ b/src/main/java/com/example/sinitto/guard/service/GuardService.java @@ -90,7 +90,8 @@ public void updateSenior(Long memberId, Long seniorId, SeniorRequest seniorReque () -> new NotFoundException("이메일에 해당하는 시니어를 찾을 수 없습니다.") ); - if(seniorRepository.existsByPhoneNumber(seniorRequest.seniorPhoneNumber())) { + if(!senior.getPhoneNumber().equals(seniorRequest.seniorPhoneNumber()) + && seniorRepository.existsByPhoneNumber(seniorRequest.seniorPhoneNumber())) { throw new BadRequestException("이미 등록되어 있는 전화번호 입니다."); } diff --git a/src/test/java/com/example/sinitto/guard/service/GuardServiceTest.java b/src/test/java/com/example/sinitto/guard/service/GuardServiceTest.java index d8dc017b..0c785010 100644 --- a/src/test/java/com/example/sinitto/guard/service/GuardServiceTest.java +++ b/src/test/java/com/example/sinitto/guard/service/GuardServiceTest.java @@ -184,6 +184,7 @@ void updateSeniorTest() { SeniorRequest request = new SeniorRequest("newSeniorName", "01011111111"); when(seniorRepository.findByIdAndMemberId(seniorId, memberId)).thenReturn(Optional.of(senior)); + when(senior.getPhoneNumber()).thenReturn("01012121212"); //when guardService.updateSenior(memberId, seniorId, request); @@ -203,6 +204,7 @@ void updateSeniorTestFailWhenDuplicatedPhoneNumber() { when(seniorRepository.findByIdAndMemberId(seniorId, memberId)).thenReturn(Optional.of(senior)); when(seniorRepository.existsByPhoneNumber("01011111111")).thenReturn(true); + when(senior.getPhoneNumber()).thenReturn("01012121212"); //when then assertThrows(BadRequestException.class, () -> guardService.updateSenior(memberId, seniorId, request)); }