diff --git a/src/main/java/in/koreatech/koin/domain/user/dto/UserTokenRefreshRequest.java b/src/main/java/in/koreatech/koin/domain/user/dto/UserTokenRefreshRequest.java index cbe02da56..c2955a01d 100644 --- a/src/main/java/in/koreatech/koin/domain/user/dto/UserTokenRefreshRequest.java +++ b/src/main/java/in/koreatech/koin/domain/user/dto/UserTokenRefreshRequest.java @@ -1,12 +1,13 @@ package in.koreatech.koin.domain.user.dto; +import com.fasterxml.jackson.annotation.JsonProperty; 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 + @JsonProperty("refresh_token") @NotNull(message = "refresh_token을 입력해주세요.") String refreshToken ) { } diff --git a/src/main/java/in/koreatech/koin/domain/user/service/UserService.java b/src/main/java/in/koreatech/koin/domain/user/service/UserService.java index 22a5ed296..f86a148a7 100644 --- a/src/main/java/in/koreatech/koin/domain/user/service/UserService.java +++ b/src/main/java/in/koreatech/koin/domain/user/service/UserService.java @@ -52,7 +52,7 @@ public void logout(User user) { public UserTokenRefreshResponse refresh(User user, UserTokenRefreshRequest request) { UserToken userToken = userTokenRepository.findById(user.getId()) .orElseThrow(() -> new IllegalArgumentException("refresh token이 존재하지 않습니다. request: " + request)); - if (Objects.equals(userToken.getRefreshToken(), request.refreshToken())) { + if (!Objects.equals(userToken.getRefreshToken(), request.refreshToken())) { throw new IllegalArgumentException("refresh token이 일치하지 않습니다. request: " + request); } String accessToken = jwtProvider.createToken(user); diff --git a/src/test/java/in/koreatech/koin/acceptance/AuthApiTest.java b/src/test/java/in/koreatech/koin/acceptance/AuthApiTest.java index 4e46b3bca..652e35773 100644 --- a/src/test/java/in/koreatech/koin/acceptance/AuthApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/AuthApiTest.java @@ -12,6 +12,7 @@ import io.restassured.http.ContentType; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +import java.util.Map; import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -165,16 +166,27 @@ void userRefreshToken() { .given() .log().all() .header("Authorization", "BEARER " + response.jsonPath().getString("token")) + .body( + Map.of("refresh_token", response.jsonPath().getString("refresh_token")) + ) + .contentType(ContentType.JSON) .when() .log().all() - .post("/user/logout") + .post("/user/refresh") .then() .log().all() .statusCode(HttpStatus.OK.value()) .extract(); - Optional token = tokenRepository.findById(user.getId()); + UserToken token = tokenRepository.findById(user.getId()).get(); - Assertions.assertThat(token).isEmpty(); + assertSoftly( + softly -> { + softly.assertThat(response.jsonPath().getString("token")).isNotNull(); + softly.assertThat(response.jsonPath().getString("refresh_token")).isNotNull(); + softly.assertThat(response.jsonPath().getString("refresh_token")) + .isEqualTo(token.getRefreshToken()); + } + ); } }