-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
로그인 권한 없이 비밀번호 변경하기 API
- Loading branch information
Showing
9 changed files
with
167 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ava/com/ajou/hertz/domain/user/controller/UpdatePasswordWithoutAuthenticationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ajou.hertz.domain.user.controller; | ||
|
||
import com.ajou.hertz.common.validator.Password; | ||
import com.ajou.hertz.common.validator.PhoneNumber; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class UpdatePasswordWithoutAuthenticationRequest { | ||
|
||
@Schema(description = "전화번호", example = "01012345678") | ||
@PhoneNumber | ||
@NotBlank | ||
private String phoneNumber; | ||
|
||
@Schema(description = "비밀번호", example = "newpwd1234!!") | ||
@NotBlank | ||
@Password | ||
private String password; | ||
|
||
@Schema(description = "SMS 본인인증 시 발급받은 인증번호", example = "1a2b3c4d") | ||
@NotBlank | ||
private String userAuthCode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import com.ajou.hertz.domain.user.controller.UpdatePasswordWithoutAuthenticationRequest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
@@ -258,6 +259,28 @@ static Stream<Arguments> testDataForCreateNewUserWithKakao() throws Exception { | |
assertThat(updatedUserDto.getPassword()).isEqualTo(newPassword); | ||
} | ||
|
||
@Test | ||
void 주어진_전화번호에_해당하는_유저의_비밀번호를_변경한다() throws Exception { | ||
// given | ||
Long userId = 1L; | ||
String phoneNumber = "01012345678"; | ||
String newPassword = "newPwd1234!!"; | ||
UpdatePasswordWithoutAuthenticationRequest updatePasswordRequest = | ||
createUpdatePasswordWithoutAuthenticationRequest(phoneNumber, newPassword); | ||
User user = createUser(userId, "$2a$abc123", "12345"); | ||
given(userQueryService.getByPhone(phoneNumber)).willReturn(user); | ||
given(passwordEncoder.encode(newPassword)).willReturn(newPassword); | ||
|
||
// when | ||
UserDto updatedUserDto = sut.updatePassword(updatePasswordRequest); | ||
|
||
// then | ||
then(userQueryService).should().getByPhone(phoneNumber); | ||
then(passwordEncoder).should().encode(newPassword); | ||
verifyEveryMocksShouldHaveNoMoreInteractions(); | ||
assertThat(updatedUserDto.getPassword()).isEqualTo(newPassword); | ||
} | ||
|
||
private void verifyEveryMocksShouldHaveNoMoreInteractions() { | ||
then(userQueryService).shouldHaveNoMoreInteractions(); | ||
then(userRepository).shouldHaveNoMoreInteractions(); | ||
|
@@ -299,6 +322,17 @@ private SignUpRequest createSignUpRequest() throws Exception { | |
return createSignUpRequest("[email protected]", "01012345678"); | ||
} | ||
|
||
private UpdatePasswordWithoutAuthenticationRequest createUpdatePasswordWithoutAuthenticationRequest( | ||
String phoneNumber, | ||
String newPassword | ||
) throws Exception { | ||
return ReflectionUtils.createUpdatePasswordWithoutAuthenticationRequest( | ||
phoneNumber, | ||
newPassword, | ||
"1a2s3d4f" | ||
); | ||
} | ||
|
||
private static KakaoUserInfoResponse createKakaoUserInfoResponse(String gender) { | ||
return new KakaoUserInfoResponse( | ||
"12345", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters