diff --git a/src/main/java/coffeemeet/server/auth/controller/AuthController.java b/src/main/java/coffeemeet/server/auth/controller/AuthController.java index 5ba14558..d2549563 100644 --- a/src/main/java/coffeemeet/server/auth/controller/AuthController.java +++ b/src/main/java/coffeemeet/server/auth/controller/AuthController.java @@ -12,7 +12,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/auth") +@RequestMapping("/api/v1/auth") public class AuthController { private final AuthService authService; diff --git a/src/main/java/coffeemeet/server/oauth/client/OAuthMemberClient.java b/src/main/java/coffeemeet/server/oauth/client/OAuthMemberClient.java index a3f81b1f..7a13eeea 100644 --- a/src/main/java/coffeemeet/server/oauth/client/OAuthMemberClient.java +++ b/src/main/java/coffeemeet/server/oauth/client/OAuthMemberClient.java @@ -1,12 +1,12 @@ package coffeemeet.server.oauth.client; -import coffeemeet.server.oauth.dto.OAuthInfoDto; +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; import coffeemeet.server.user.domain.OAuthProvider; public interface OAuthMemberClient { OAuthProvider oAuthProvider(); - OAuthInfoDto.Response fetch(String authCode); + OAuthUserInfoDto.Response fetch(String authCode); } diff --git a/src/main/java/coffeemeet/server/oauth/client/OAuthMemberClientComposite.java b/src/main/java/coffeemeet/server/oauth/client/OAuthMemberClientComposite.java index 71796d74..b240569b 100644 --- a/src/main/java/coffeemeet/server/oauth/client/OAuthMemberClientComposite.java +++ b/src/main/java/coffeemeet/server/oauth/client/OAuthMemberClientComposite.java @@ -1,6 +1,6 @@ package coffeemeet.server.oauth.client; -import coffeemeet.server.oauth.dto.OAuthInfoDto; +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; import coffeemeet.server.user.domain.OAuthProvider; import java.util.Map; import java.util.Optional; @@ -21,7 +21,7 @@ public OAuthMemberClientComposite(Set clients) { ); } - public OAuthInfoDto.Response fetch(OAuthProvider oAuthProvider, String authCode) { + public OAuthUserInfoDto.Response fetch(OAuthProvider oAuthProvider, String authCode) { return getClient(oAuthProvider).fetch(authCode); } diff --git a/src/main/java/coffeemeet/server/oauth/dto/OAuthInfoDto.java b/src/main/java/coffeemeet/server/oauth/dto/OAuthUserInfoDto.java similarity index 76% rename from src/main/java/coffeemeet/server/oauth/dto/OAuthInfoDto.java rename to src/main/java/coffeemeet/server/oauth/dto/OAuthUserInfoDto.java index 9442fd87..0a1c1782 100644 --- a/src/main/java/coffeemeet/server/oauth/dto/OAuthInfoDto.java +++ b/src/main/java/coffeemeet/server/oauth/dto/OAuthUserInfoDto.java @@ -2,7 +2,7 @@ import coffeemeet.server.user.domain.OAuthProvider; -public sealed interface OAuthInfoDto permits OAuthInfoDto.Response { +public sealed interface OAuthUserInfoDto permits OAuthUserInfoDto.Response { record Response( String name, @@ -12,9 +12,9 @@ record Response( String email, OAuthProvider oAuthProvider, String oAuthProviderId - ) implements OAuthInfoDto { + ) implements OAuthUserInfoDto { - public static OAuthInfoDto.Response of( + public static OAuthUserInfoDto.Response of( String name, String profileImage, String birthYear, @@ -23,7 +23,7 @@ public static OAuthInfoDto.Response of( OAuthProvider oAuthProvider, String oAuthProviderId ) { - return new OAuthInfoDto.Response( + return new OAuthUserInfoDto.Response( name, profileImage, birthYear, diff --git a/src/main/java/coffeemeet/server/oauth/infrastructure/kakao/client/KakaoMemberClient.java b/src/main/java/coffeemeet/server/oauth/infrastructure/kakao/client/KakaoMemberClient.java index 1cc51007..d9343906 100644 --- a/src/main/java/coffeemeet/server/oauth/infrastructure/kakao/client/KakaoMemberClient.java +++ b/src/main/java/coffeemeet/server/oauth/infrastructure/kakao/client/KakaoMemberClient.java @@ -1,7 +1,7 @@ package coffeemeet.server.oauth.infrastructure.kakao.client; import coffeemeet.server.oauth.client.OAuthMemberClient; -import coffeemeet.server.oauth.dto.OAuthInfoDto; +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; import coffeemeet.server.oauth.infrastructure.kakao.dto.KakaoMemberResponse; import coffeemeet.server.oauth.infrastructure.kakao.dto.KakaoTokens; import coffeemeet.server.user.domain.OAuthProvider; @@ -20,7 +20,7 @@ public OAuthProvider oAuthProvider() { } @Override - public OAuthInfoDto.Response fetch(String authCode) { + public OAuthUserInfoDto.Response fetch(String authCode) { KakaoTokens tokenInfo = kakaoApiClient.fetchToken(authCode); KakaoMemberResponse response = kakaoApiClient.fetchMember(tokenInfo.accessToken()); diff --git a/src/main/java/coffeemeet/server/oauth/infrastructure/kakao/dto/KakaoMemberResponse.java b/src/main/java/coffeemeet/server/oauth/infrastructure/kakao/dto/KakaoMemberResponse.java index 0863930e..12acbdea 100644 --- a/src/main/java/coffeemeet/server/oauth/infrastructure/kakao/dto/KakaoMemberResponse.java +++ b/src/main/java/coffeemeet/server/oauth/infrastructure/kakao/dto/KakaoMemberResponse.java @@ -1,6 +1,6 @@ package coffeemeet.server.oauth.infrastructure.kakao.dto; -import coffeemeet.server.oauth.dto.OAuthInfoDto; +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; import coffeemeet.server.user.domain.OAuthProvider; import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -11,8 +11,8 @@ public record KakaoMemberResponse( KakaoAccount kakaoAccount ) { - public OAuthInfoDto.Response toOAuthInfoResponse() { - return OAuthInfoDto.Response.of( + public OAuthUserInfoDto.Response toOAuthInfoResponse() { + return OAuthUserInfoDto.Response.of( kakaoAccount.name, kakaoAccount.profile.profileImageUrl, kakaoAccount.birthyear, diff --git a/src/main/java/coffeemeet/server/oauth/service/OAuthService.java b/src/main/java/coffeemeet/server/oauth/service/OAuthService.java index 29aac986..07b7b1c4 100644 --- a/src/main/java/coffeemeet/server/oauth/service/OAuthService.java +++ b/src/main/java/coffeemeet/server/oauth/service/OAuthService.java @@ -2,7 +2,7 @@ import coffeemeet.server.oauth.authcode.AuthCodeRequestUrlProviderComposite; import coffeemeet.server.oauth.client.OAuthMemberClientComposite; -import coffeemeet.server.oauth.dto.OAuthInfoDto; +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; import coffeemeet.server.user.domain.OAuthProvider; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -18,7 +18,7 @@ public String getAuthCodeRequestUrl(OAuthProvider oAuthProvider) { return authCodeRequestUrlProviderComposite.provide(oAuthProvider); } - public OAuthInfoDto.Response getOAuthInfo(OAuthProvider oAuthProvider, String authCode) { + public OAuthUserInfoDto.Response getOAuthInfo(OAuthProvider oAuthProvider, String authCode) { return oauthMemberClientComposite.fetch(oAuthProvider, authCode); } diff --git a/src/main/java/coffeemeet/server/user/service/UserService.java b/src/main/java/coffeemeet/server/user/service/UserService.java index ae0130be..9cf0c36d 100644 --- a/src/main/java/coffeemeet/server/user/service/UserService.java +++ b/src/main/java/coffeemeet/server/user/service/UserService.java @@ -11,7 +11,7 @@ import coffeemeet.server.interest.domain.Keyword; import coffeemeet.server.interest.repository.InterestRepository; import coffeemeet.server.interest.service.InterestService; -import coffeemeet.server.oauth.dto.OAuthInfoDto; +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; import coffeemeet.server.oauth.service.OAuthService; import coffeemeet.server.user.domain.Birth; import coffeemeet.server.user.domain.Email; @@ -94,7 +94,7 @@ public void updateProfileInfo(Long userId, String nickname, String name, @Transactional public AuthTokens signup(SignupRequest request) { - OAuthInfoDto.Response response = oAuthService.getOAuthInfo(request.oAuthProvider(), + OAuthUserInfoDto.Response response = oAuthService.getOAuthInfo(request.oAuthProvider(), request.authCode()); checkDuplicatedUser(response); @@ -113,7 +113,7 @@ public AuthTokens signup(SignupRequest request) { } public AuthTokens login(OAuthProvider oAuthProvider, String authCode) { - OAuthInfoDto.Response response = oAuthService.getOAuthInfo(oAuthProvider, authCode); + OAuthUserInfoDto.Response response = oAuthService.getOAuthInfo(oAuthProvider, authCode); User foundUser = userRepository.getUserByOauthInfoOauthProviderAndOauthInfoOauthProviderId( response.oAuthProvider(), response.oAuthProviderId()).orElseThrow( () -> new IllegalArgumentException( @@ -134,7 +134,7 @@ public void checkDuplicatedNickname(String nickname) { } } - public void checkDuplicatedUser(OAuthInfoDto.Response response) { + public void checkDuplicatedUser(OAuthUserInfoDto.Response response) { if (userRepository.existsUserByOauthInfo_oauthProviderAndOauthInfo_oauthProviderId( response.oAuthProvider(), response.oAuthProviderId())) { throw new IllegalArgumentException(ALREADY_REGISTERED_MESSAGE); diff --git a/src/test/java/coffeemeet/server/auth/controller/AuthControllerTest.java b/src/test/java/coffeemeet/server/auth/controller/AuthControllerTest.java new file mode 100644 index 00000000..4387a1f6 --- /dev/null +++ b/src/test/java/coffeemeet/server/auth/controller/AuthControllerTest.java @@ -0,0 +1,125 @@ +package coffeemeet.server.auth.controller; + +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.resourceDetails; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willDoNothing; +import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import coffeemeet.server.auth.domain.AuthTokens; +import coffeemeet.server.auth.domain.RefreshToken; +import coffeemeet.server.auth.service.AuthService; +import coffeemeet.server.common.config.ControllerTestConfig; +import coffeemeet.server.common.fixture.dto.AuthTokensFixture; +import coffeemeet.server.common.fixture.dto.RefreshTokenFixture; +import com.epages.restdocs.apispec.Schema; +import java.util.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.restdocs.payload.JsonFieldType; + +@WebMvcTest(AuthController.class) +class AuthControllerTest extends ControllerTestConfig { + + @MockBean + private AuthService authService; + + @DisplayName("refresh token 을 통해 access token 을 갱신할 수 있다.") + @Test + void renewTest() throws Exception { + // given + AuthTokens authTokens = AuthTokensFixture.authTokens(); + RefreshToken refreshToken = RefreshTokenFixture.refreshToken(); + + given(authService.renew(anyLong(), any())).willReturn(authTokens); + given(refreshTokenRepository.findById(anyLong())).willReturn(Optional.ofNullable(refreshToken)); + + // when, then + mockMvc.perform(post("/api/v1/auth/renew-token") + .header("Authorization", TOKEN) + .contentType(MediaType.APPLICATION_JSON) + ) + .andDo(document("auth-renew", + resourceDetails().tag("인증").description("토큰 갱신") + .responseSchema(Schema.schema("AuthTokens")), + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestHeaders( + headerWithName("Authorization").description("토큰") + ), + responseFields( + fieldWithPath("accessToken").type(JsonFieldType.STRING).description("액세스 토큰"), + fieldWithPath("refreshToken").type(JsonFieldType.STRING).description("리프레시 토큰") + ) + ) + ) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.accessToken").value(authTokens.accessToken())) + .andExpect(jsonPath("$.refreshToken").value(authTokens.refreshToken())); + } + + @DisplayName("사용자는 로그아웃 할 수 있다.") + @Test + void logoutTest() throws Exception { + // given + RefreshToken refreshToken = RefreshTokenFixture.refreshToken(); + willDoNothing().given(authService).logout(anyLong()); + given(refreshTokenRepository.findById(anyLong())).willReturn(Optional.ofNullable(refreshToken)); + + // when, then + mockMvc.perform(post("/api/v1/auth/logout") + .header("Authorization", TOKEN) + .contentType(MediaType.APPLICATION_JSON) + ) + .andDo(document("auth-logout", + resourceDetails().tag("인증").description("로그아웃"), + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestHeaders( + headerWithName("Authorization").description("토큰") + ) + ) + ) + .andExpect(status().isOk()); + } + + @DisplayName("사용자는 회원탈퇴 할 수 있다.") + @Test + void deleteTest() throws Exception { + // given + RefreshToken refreshToken = RefreshTokenFixture.refreshToken(); + willDoNothing().given(authService).delete(anyLong()); + given(refreshTokenRepository.findById(anyLong())).willReturn(Optional.ofNullable(refreshToken)); + + // when, then + mockMvc.perform(post("/api/v1/auth/delete") + .header("Authorization", TOKEN) + .contentType(MediaType.APPLICATION_JSON) + ) + .andDo(document("auth-delete", + resourceDetails().tag("인증").description("회원탈퇴"), + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestHeaders( + headerWithName("Authorization").description("토큰") + ) + ) + ) + .andExpect(status().isOk()); + } + +} diff --git a/src/test/java/coffeemeet/server/auth/domain/AuthTokensGeneratorTest.java b/src/test/java/coffeemeet/server/auth/domain/AuthTokensGeneratorTest.java new file mode 100644 index 00000000..09de8058 --- /dev/null +++ b/src/test/java/coffeemeet/server/auth/domain/AuthTokensGeneratorTest.java @@ -0,0 +1,78 @@ +package coffeemeet.server.auth.domain; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; + +import coffeemeet.server.auth.repository.RefreshTokenRepository; +import java.util.Date; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class AuthTokensGeneratorTest { + + private static final Long accessTokenExpireTime = 1800L; + private static final Long refreshTokenExpireTime = 3600L; + private static final String BEARER_TYPE = "Bearer "; + private static final String ACCESS_TOKEN = "accessToken"; + private static final String REFRESH_TOKEN = "refreshToken"; + + @InjectMocks + private AuthTokensGenerator authTokensGenerator; + + @Mock + private JwtTokenProvider jwtTokenProvider; + + @Mock + private RefreshTokenRepository refreshTokenRepository; + + @BeforeEach + public void init() { + authTokensGenerator = new AuthTokensGenerator(jwtTokenProvider, accessTokenExpireTime, + refreshTokenExpireTime, refreshTokenRepository); + } + + @DisplayName("access token & refresh token 발급할 수 있다.") + @Test + void generateTest() { + // given + given(jwtTokenProvider.generate(anyString(), any(Date.class))).willReturn(ACCESS_TOKEN, + REFRESH_TOKEN); + + // when + AuthTokens authTokens = authTokensGenerator.generate((long) Math.random()); + + // then + assertAll( + () -> assertThat(authTokens.accessToken()).isEqualTo(BEARER_TYPE + ACCESS_TOKEN), + () -> assertThat(authTokens.refreshToken()).isEqualTo(BEARER_TYPE + REFRESH_TOKEN) + ); + } + + @DisplayName("access token 을 갱신 할 수 있다.") + @Test + void reissueAccessTokenTest() { + // given + given(jwtTokenProvider.generate(anyString(), any(Date.class))).willReturn(ACCESS_TOKEN, + REFRESH_TOKEN); + + // when + AuthTokens authTokens = authTokensGenerator.reissueAccessToken((long) Math.random(), + REFRESH_TOKEN); + + // then + assertAll( + () -> assertThat(authTokens.accessToken()).isEqualTo(BEARER_TYPE + ACCESS_TOKEN), + () -> assertThat(authTokens.refreshToken()).isEqualTo(BEARER_TYPE + REFRESH_TOKEN) + ); + } + +} diff --git a/src/test/java/coffeemeet/server/auth/domain/JwtTokenProviderTest.java b/src/test/java/coffeemeet/server/auth/domain/JwtTokenProviderTest.java new file mode 100644 index 00000000..2b22d811 --- /dev/null +++ b/src/test/java/coffeemeet/server/auth/domain/JwtTokenProviderTest.java @@ -0,0 +1,64 @@ +package coffeemeet.server.auth.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.Keys; +import java.util.Base64; +import java.util.Date; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class JwtTokenProviderTest { + + private static final String SUBJECT = "123"; + private static final int ACCESS_TOKEN_EXPIRE_TIME = 3600000; + + private final String secretKey = Base64.getEncoder() + .encodeToString(Keys.secretKeyFor(SignatureAlgorithm.HS512).getEncoded()); + + private JwtTokenProvider jwtTokenProvider = new JwtTokenProvider(secretKey); + + @DisplayName("jwt 를 생성할 수 있다.") + @Test + void generate() { + // given + Date date = new Date(System.currentTimeMillis() + ACCESS_TOKEN_EXPIRE_TIME); + + // when + String result = jwtTokenProvider.generate(SUBJECT, date); + + // then + assertThat(result).isNotNull(); + } + + @DisplayName("jwt 로부터 userId 를 가져올 수 있다.") + @Test + void extractUserId() { + // given + Date date = new Date(System.currentTimeMillis() + ACCESS_TOKEN_EXPIRE_TIME); + + // when + String token = jwtTokenProvider.generate(SUBJECT, date); + Long result = jwtTokenProvider.extractUserId(token); + + // then + assertThat(result).isEqualTo(Long.parseLong(SUBJECT)); + } + + @DisplayName("jwt(refresh token) 로부터 토큰이 만료되었는지 확인할 수 있다.") + @Test + void isExpiredRefreshToken() { + // given + Date date = new Date(System.currentTimeMillis() + ACCESS_TOKEN_EXPIRE_TIME); + + String token = jwtTokenProvider.generate(SUBJECT, date); + + // when, then + assertThat(jwtTokenProvider.isExpiredRefreshToken(token)).isFalse(); + } + +} diff --git a/src/test/java/coffeemeet/server/auth/service/AuthServiceTest.java b/src/test/java/coffeemeet/server/auth/service/AuthServiceTest.java new file mode 100644 index 00000000..614b0538 --- /dev/null +++ b/src/test/java/coffeemeet/server/auth/service/AuthServiceTest.java @@ -0,0 +1,90 @@ +package coffeemeet.server.auth.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willDoNothing; + +import coffeemeet.server.auth.domain.AuthTokens; +import coffeemeet.server.auth.domain.AuthTokensGenerator; +import coffeemeet.server.auth.domain.JwtTokenProvider; +import coffeemeet.server.auth.repository.RefreshTokenRepository; +import coffeemeet.server.common.fixture.dto.AuthTokensFixture; +import coffeemeet.server.user.service.UserService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class AuthServiceTest { + + public static final String REFRESH_TOKEN = "Bearer aaaaaaaa.bbbbbbb.ccccccc"; + @InjectMocks + private AuthService authService; + + @Mock + private UserService userService; + + @Mock + private AuthTokensGenerator authTokensGenerator; + + @Mock + private JwtTokenProvider jwtTokenProvider; + + @Mock + private RefreshTokenRepository refreshTokenRepository; + + @DisplayName("access token 을 갱신할 수 있다.") + @Test + void renew() { + // given + AuthTokens authTokens = AuthTokensFixture.authTokens(); + AuthTokens newAuthTokens = AuthTokensFixture.authTokens(REFRESH_TOKEN); + + given(jwtTokenProvider.isExpiredRefreshToken(REFRESH_TOKEN)).willReturn(false); + given(authTokensGenerator.reissueAccessToken(anyLong(), any(String.class))).willReturn( + newAuthTokens); + + // when + AuthTokens renewedAuthTokens = authService.renew((long) Math.random(), REFRESH_TOKEN); + + // then + assertAll( + () -> assertThat(renewedAuthTokens.accessToken()).isNotEqualTo(authTokens.accessToken()), + () -> assertThat(renewedAuthTokens.refreshToken()).isEqualTo(REFRESH_TOKEN) + ); + } + + @DisplayName("로그아웃 시킬 수 있다.") + @Test + void logout() { + // given + willDoNothing().given(refreshTokenRepository).deleteById(anyLong()); + + // when + authService.logout((long) Math.random()); + + // then + assertThat(true).isTrue(); + } + + @DisplayName("회원 탈퇴 시킬 수 있다.") + @Test + void delete() { + // given + willDoNothing().given(refreshTokenRepository).deleteById(anyLong()); + willDoNothing().given(userService).deleteUser(anyLong()); + + // when + authService.delete((long) Math.random()); + + // then + assertThat(true).isTrue(); + } + +} diff --git a/src/test/java/coffeemeet/server/common/fixture/dto/AuthTokensFixture.java b/src/test/java/coffeemeet/server/common/fixture/dto/AuthTokensFixture.java new file mode 100644 index 00000000..3d657555 --- /dev/null +++ b/src/test/java/coffeemeet/server/common/fixture/dto/AuthTokensFixture.java @@ -0,0 +1,21 @@ +package coffeemeet.server.common.fixture.dto; + +import static org.instancio.Select.field; + +import coffeemeet.server.auth.domain.AuthTokens; +import org.instancio.Instancio; + +public class AuthTokensFixture { + + public static AuthTokens authTokens() { + return Instancio.of(AuthTokens.class) + .create(); + } + + public static AuthTokens authTokens(String refreshToken) { + return Instancio.of(AuthTokens.class) + .set(field(AuthTokens::refreshToken), refreshToken) + .create(); + } + +} diff --git a/src/test/java/coffeemeet/server/common/fixture/dto/OAuthInfoResponseFixture.java b/src/test/java/coffeemeet/server/common/fixture/dto/OAuthInfoResponseFixture.java deleted file mode 100644 index a9e3f15f..00000000 --- a/src/test/java/coffeemeet/server/common/fixture/dto/OAuthInfoResponseFixture.java +++ /dev/null @@ -1,13 +0,0 @@ -package coffeemeet.server.common.fixture.dto; - -import coffeemeet.server.oauth.dto.OAuthInfoDto; -import org.instancio.Instancio; - -public class OAuthInfoResponseFixture { - - public static OAuthInfoDto.Response oAuthInfoResponse() { - return Instancio.of(OAuthInfoDto.Response.class) - .create(); - } - -} diff --git a/src/test/java/coffeemeet/server/common/fixture/dto/OAuthUserInfoDtoFixture.java b/src/test/java/coffeemeet/server/common/fixture/dto/OAuthUserInfoDtoFixture.java new file mode 100644 index 00000000..4ddb409f --- /dev/null +++ b/src/test/java/coffeemeet/server/common/fixture/dto/OAuthUserInfoDtoFixture.java @@ -0,0 +1,13 @@ +package coffeemeet.server.common.fixture.dto; + +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; +import org.instancio.Instancio; + +public class OAuthUserInfoDtoFixture { + + public static OAuthUserInfoDto.Response response() { + return Instancio.of(OAuthUserInfoDto.Response.class) + .create(); + } + +} diff --git a/src/test/java/coffeemeet/server/common/fixture/dto/RefreshTokenFixture.java b/src/test/java/coffeemeet/server/common/fixture/dto/RefreshTokenFixture.java new file mode 100644 index 00000000..9140ba1a --- /dev/null +++ b/src/test/java/coffeemeet/server/common/fixture/dto/RefreshTokenFixture.java @@ -0,0 +1,13 @@ +package coffeemeet.server.common.fixture.dto; + +import coffeemeet.server.auth.domain.RefreshToken; +import org.instancio.Instancio; + +public class RefreshTokenFixture { + + public static RefreshToken refreshToken() { + return Instancio.of(RefreshToken.class) + .create(); + } + +} diff --git a/src/test/java/coffeemeet/server/oauth/client/OAuthMemberClientCompositeTest.java b/src/test/java/coffeemeet/server/oauth/client/OAuthMemberClientCompositeTest.java index 324dc45d..96952a18 100644 --- a/src/test/java/coffeemeet/server/oauth/client/OAuthMemberClientCompositeTest.java +++ b/src/test/java/coffeemeet/server/oauth/client/OAuthMemberClientCompositeTest.java @@ -3,8 +3,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; -import coffeemeet.server.common.fixture.dto.OAuthInfoResponseFixture; -import coffeemeet.server.oauth.dto.OAuthInfoDto; +import coffeemeet.server.common.fixture.dto.OAuthUserInfoDtoFixture; +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; import coffeemeet.server.user.domain.OAuthProvider; import java.util.Collections; import java.util.HashSet; @@ -34,7 +34,7 @@ void fetchTest() { // given String authCode = "authCode"; OAuthProvider oAuthProvider = OAuthProvider.KAKAO; - OAuthInfoDto.Response response = OAuthInfoResponseFixture.oAuthInfoResponse(); + OAuthUserInfoDto.Response response = OAuthUserInfoDtoFixture.response(); given(client.oAuthProvider()).willReturn(OAuthProvider.KAKAO); given(client.fetch(authCode)).willReturn(response); @@ -43,7 +43,7 @@ void fetchTest() { composite = new OAuthMemberClientComposite(clients); // when - OAuthInfoDto.Response expectedResponse = composite.fetch(oAuthProvider, authCode); + OAuthUserInfoDto.Response expectedResponse = composite.fetch(oAuthProvider, authCode); // then assertThat(response).isEqualTo(expectedResponse); diff --git a/src/test/java/coffeemeet/server/oauth/service/OAuthServiceTest.java b/src/test/java/coffeemeet/server/oauth/service/OAuthServiceTest.java index 96d368f5..66176595 100644 --- a/src/test/java/coffeemeet/server/oauth/service/OAuthServiceTest.java +++ b/src/test/java/coffeemeet/server/oauth/service/OAuthServiceTest.java @@ -3,10 +3,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; -import coffeemeet.server.common.fixture.dto.OAuthInfoResponseFixture; +import coffeemeet.server.common.fixture.dto.OAuthUserInfoDtoFixture; import coffeemeet.server.oauth.authcode.AuthCodeRequestUrlProviderComposite; import coffeemeet.server.oauth.client.OAuthMemberClientComposite; -import coffeemeet.server.oauth.dto.OAuthInfoDto; +import coffeemeet.server.oauth.dto.OAuthUserInfoDto; import coffeemeet.server.user.domain.OAuthProvider; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -48,7 +48,7 @@ void getOAuthInfoTest() { // given OAuthProvider oAuthProvider = OAuthProvider.KAKAO; String authCode = "authCode"; - OAuthInfoDto.Response oAuthInfoResponse = OAuthInfoResponseFixture.oAuthInfoResponse(); + OAuthUserInfoDto.Response oAuthInfoResponse = OAuthUserInfoDtoFixture.response(); given(oAuthMemberClientComposite.fetch(oAuthProvider, authCode)).willReturn(oAuthInfoResponse);