Skip to content

Commit

Permalink
fix: 응답 수정 및 테스트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Choi-JJunho committed Jan 9, 2024
1 parent c2709da commit 6402566
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 15 additions & 3 deletions src/test/java/in/koreatech/koin/acceptance/AuthApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<UserToken> 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());
}
);
}
}

0 comments on commit 6402566

Please sign in to comment.