refactor: modifyPassword -> changePassword 네이밍 변경
This commit is contained in:
@@ -43,13 +43,13 @@ public class UserController {
|
||||
}
|
||||
|
||||
@PatchMapping("/password")
|
||||
public ResponseEntity<Object> modifyPassword(@RequestBody @Valid UserModifyPasswordRequest request) {
|
||||
public ResponseEntity<Object> changePassword(@RequestBody @Valid UserModifyPasswordRequest request) {
|
||||
if (request.oldEqualNew()) {
|
||||
log.error("기존 패스워드와 동일한 패스워드로 변경할 수 없습니다.");
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||
}
|
||||
|
||||
User user = userService.modifyPassword(request.toChangePassword(passwordEncoder));
|
||||
User user = userService.changePassword(request.toChangePassword(passwordEncoder));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(UserModifyPasswordResponse.of(user));
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class User extends AbstractEntity {
|
||||
return this;
|
||||
}
|
||||
|
||||
public User modifyPassword(ChangePasswordDTO changePassword) {
|
||||
public User changePassword(ChangePasswordDTO changePassword) {
|
||||
checkPassword(changePassword);
|
||||
|
||||
this.password = changePassword.getEncodePassword();
|
||||
|
||||
@@ -51,7 +51,7 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public User modifyPassword(@Valid ChangePasswordDTO changePassword) {
|
||||
public User changePassword(@Valid ChangePasswordDTO changePassword) {
|
||||
Optional<User> optionalUser = userRepository.findByEmailAndIsDeletedFalse(changePassword.getEmail());
|
||||
if (optionalUser.isEmpty()) {
|
||||
log.error("존재하지 않는 이메일 입니다. :: {}", changePassword);
|
||||
@@ -59,7 +59,7 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
User user = optionalUser.get();
|
||||
return user.modifyPassword(changePassword);
|
||||
return user.changePassword(changePassword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ public interface UserService {
|
||||
|
||||
User delete(@Valid DeleteUserDTO deleteUser);
|
||||
|
||||
User modifyPassword(@Valid ChangePasswordDTO changePassword);
|
||||
User changePassword(@Valid ChangePasswordDTO changePassword);
|
||||
|
||||
}
|
||||
|
||||
@@ -154,27 +154,27 @@ class UserTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("입력받은 패스워드와 불일치로 변경 실패")
|
||||
void modifyPasswordFail() {
|
||||
void changePasswordFail() {
|
||||
// given
|
||||
ChangePasswordDTO changePassword = new ChangePasswordDTO("ticketing@gmail.com", "1234567", "ticketing1234", DeleteUserTest.CUSTOM_PASSWORD_ENCODER);
|
||||
User user = new User("유저1", "ticketing@gmail.com", "123456", UserGrade.GUEST, "010-1234-5678");
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> user.modifyPassword(changePassword))
|
||||
assertThatThrownBy(() -> user.changePassword(changePassword))
|
||||
.isInstanceOf(PasswordMismatchException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("패스워드 변경 성공")
|
||||
void modifyPasswordSuccess() {
|
||||
void changePasswordSuccess() {
|
||||
// given
|
||||
ChangePasswordDTO changePassword = new ChangePasswordDTO("ticketing@gmail.com", "123456", "ticketing1234", DeleteUserTest.CUSTOM_PASSWORD_ENCODER);
|
||||
User user = new User("유저1", "ticketing@gmail.com", "123456", UserGrade.GUEST, "010-1234-5678");
|
||||
String oldPassword = user.getPassword();
|
||||
|
||||
// when
|
||||
User modifiedUser = user.modifyPassword(changePassword);
|
||||
User modifiedUser = user.changePassword(changePassword);
|
||||
|
||||
// then
|
||||
assertThat(modifiedUser.getPassword()).isNotEqualTo(oldPassword);
|
||||
|
||||
@@ -97,24 +97,24 @@ class UserServiceImplTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("패스워드 변경 시 이메일이 존재하지 않을 경우")
|
||||
void modifyPasswordFail() {
|
||||
void changePasswordFail() {
|
||||
// given
|
||||
when(userRepository.findByEmailAndIsDeletedFalse("ticketing@gmail.com")).thenReturn(Optional.empty());
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> userService.modifyPassword(changePassword))
|
||||
assertThatThrownBy(() -> userService.changePassword(changePassword))
|
||||
.isInstanceOf(NotFoundEmailException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("패스워드 변경 성공했을 경우")
|
||||
void modifyPasswordSuccess() {
|
||||
void changePasswordSuccess() {
|
||||
// given
|
||||
when(userRepository.findByEmailAndIsDeletedFalse("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
||||
|
||||
// when
|
||||
User user = userService.modifyPassword(changePassword);
|
||||
User user = userService.changePassword(changePassword);
|
||||
|
||||
// then
|
||||
assertThat(user).isNotNull();
|
||||
|
||||
Reference in New Issue
Block a user