-
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.
- Loading branch information
1 parent
038b9ed
commit c2709da
Showing
5 changed files
with
100 additions
and
0 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
12 changes: 12 additions & 0 deletions
12
src/main/java/in/koreatech/koin/domain/user/dto/UserTokenRefreshRequest.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,12 @@ | ||
package in.koreatech.koin.domain.user.dto; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
@JsonNaming(value = SnakeCaseStrategy.class) | ||
public record UserTokenRefreshRequest( | ||
@NotNull(message = "refresh_token을 입력해주세요.") String refreshToken | ||
) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/in/koreatech/koin/domain/user/dto/UserTokenRefreshResponse.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,13 @@ | ||
package in.koreatech.koin.domain.user.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record UserTokenRefreshResponse( | ||
@JsonProperty("token") String accessToken, | ||
@JsonProperty("refresh_token") String refreshToken | ||
) { | ||
|
||
public static UserTokenRefreshResponse of(String accessToken, String refreshToken) { | ||
return new UserTokenRefreshResponse(accessToken, refreshToken); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -126,4 +126,55 @@ void userLogoutSuccess() { | |
|
||
Assertions.assertThat(token).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("사용자가 로그인 이후 refreshToken을 재발급한다") | ||
void userRefreshToken() { | ||
User user = User.builder() | ||
.password("1234") | ||
.nickname("주노") | ||
.name("최준호") | ||
.phoneNumber("010-1234-5678") | ||
.userType(UserType.USER) | ||
.email("[email protected]") | ||
.isAuthed(true) | ||
.isDeleted(false) | ||
.build(); | ||
|
||
userRepository.save(user); | ||
|
||
ExtractableResponse<Response> response = RestAssured | ||
.given() | ||
.log().all() | ||
.body(""" | ||
{ | ||
"email": "[email protected]", | ||
"password": "1234" | ||
} | ||
""") | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.log().all() | ||
.post("/user/login") | ||
.then() | ||
.log().all() | ||
.statusCode(HttpStatus.CREATED.value()) | ||
.extract(); | ||
|
||
RestAssured | ||
.given() | ||
.log().all() | ||
.header("Authorization", "BEARER " + response.jsonPath().getString("token")) | ||
.when() | ||
.log().all() | ||
.post("/user/logout") | ||
.then() | ||
.log().all() | ||
.statusCode(HttpStatus.OK.value()) | ||
.extract(); | ||
|
||
Optional<UserToken> token = tokenRepository.findById(user.getId()); | ||
|
||
Assertions.assertThat(token).isEmpty(); | ||
} | ||
} |