diff --git a/src/main/java/org/runimo/runimo/auth/test/TestAuthService.java b/src/main/java/org/runimo/runimo/auth/test/TestAuthService.java index fbc5bde4..ab3d7eeb 100644 --- a/src/main/java/org/runimo/runimo/auth/test/TestAuthService.java +++ b/src/main/java/org/runimo/runimo/auth/test/TestAuthService.java @@ -4,6 +4,8 @@ import lombok.RequiredArgsConstructor; import org.runimo.runimo.auth.exceptions.SignUpException; import org.runimo.runimo.auth.jwt.JwtTokenFactory; +import org.runimo.runimo.auth.service.TokenRefreshService; +import org.runimo.runimo.auth.service.dto.TokenPair; import org.runimo.runimo.rewards.service.eggs.EggGrantService; import org.runimo.runimo.user.domain.Gender; import org.runimo.runimo.user.domain.User; @@ -25,13 +27,16 @@ public class TestAuthService { private final UserCreator userCreator; private final UserItemCreator userItemCreator; private final EggGrantService eggGrantService; + private final TokenRefreshService tokenRefreshService; @Transactional public TestAuthResponse login(Long userId) { User user = userRepository.findById(userId) .orElseThrow(() -> SignUpException.of(UserHttpResponseCode.LOGIN_FAIL_NOT_SIGN_IN)); - return new TestAuthResponse(jwtTokenFactory.generateTokenPair(user)); + TokenPair pair = jwtTokenFactory.generateTokenPair(user); + tokenRefreshService.putRefreshToken(user.getPublicId(), pair.refreshToken()); + return new TestAuthResponse(pair); } @Transactional diff --git a/src/test/java/org/runimo/runimo/auth/service/TokenRefreshAcceptanceTest.java b/src/test/java/org/runimo/runimo/auth/controller/TokenRefreshAcceptanceTest.java similarity index 82% rename from src/test/java/org/runimo/runimo/auth/service/TokenRefreshAcceptanceTest.java rename to src/test/java/org/runimo/runimo/auth/controller/TokenRefreshAcceptanceTest.java index 5a0ebc75..a00bf725 100644 --- a/src/test/java/org/runimo/runimo/auth/service/TokenRefreshAcceptanceTest.java +++ b/src/test/java/org/runimo/runimo/auth/controller/TokenRefreshAcceptanceTest.java @@ -1,6 +1,7 @@ -package org.runimo.runimo.auth.service; +package org.runimo.runimo.auth.controller; import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.notNullValue; import static org.mockito.ArgumentMatchers.any; import com.auth0.jwt.interfaces.DecodedJWT; @@ -15,6 +16,7 @@ import org.runimo.runimo.auth.jwt.JwtTokenFactory; import org.runimo.runimo.auth.service.apple.KakaoUserInfo; import org.runimo.runimo.auth.service.kakao.KakaoTokenVerifier; +import org.runimo.runimo.auth.test.TestAuthRequest; import org.runimo.runimo.user.UserFixtures; import org.runimo.runimo.user.domain.OAuthInfo; import org.runimo.runimo.user.domain.SocialProvider; @@ -139,4 +141,28 @@ void setup() { } + @Test + void 테스트_로그인_후_리프레쉬_성공() throws JsonProcessingException { + TestAuthRequest request = new TestAuthRequest(1L); + String refreshToken = given() + .contentType("application/json") + .body(objectMapper.writeValueAsString(request)) + .when() + .post("/api/v1/auth/test/login") + .then() + .statusCode(HttpStatus.OK.value()) + .extract() + .path("payload.tokens.refresh_token"); + + given() + .header("Authorization", "Bearer " + refreshToken) + .when() + .post("/api/v1/auth/refresh") + .then() + .log().all() + .statusCode(HttpStatus.OK.value()) + .body("payload.access_token", notNullValue()) + .body("payload.refresh_token", notNullValue()); + } + }