-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#36 oauth 도메인 테스트 코드 작성
- Loading branch information
Showing
20 changed files
with
489 additions
and
65 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/main/java/coffeemeet/server/oauth/client/OAuthMemberClient.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package coffeemeet.server.oauth.client; | ||
|
||
import coffeemeet.server.oauth.dto.OAuthInfoResponse; | ||
import coffeemeet.server.oauth.dto.OAuthInfoDto; | ||
import coffeemeet.server.user.domain.OAuthProvider; | ||
|
||
public interface OAuthMemberClient { | ||
|
||
OAuthProvider oAuthProvider(); | ||
|
||
OAuthInfoResponse fetch(String authCode); | ||
OAuthInfoDto.Response fetch(String authCode); | ||
|
||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/coffeemeet/server/oauth/dto/OAuthInfoDto.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,38 @@ | ||
package coffeemeet.server.oauth.dto; | ||
|
||
import coffeemeet.server.user.domain.OAuthProvider; | ||
|
||
public sealed interface OAuthInfoDto permits OAuthInfoDto.Response { | ||
|
||
record Response( | ||
String name, | ||
String profileImage, | ||
String birthYear, | ||
String birthDay, | ||
String email, | ||
OAuthProvider oAuthProvider, | ||
String oAuthProviderId | ||
) implements OAuthInfoDto { | ||
|
||
public static OAuthInfoDto.Response of( | ||
String name, | ||
String profileImage, | ||
String birthYear, | ||
String birthDay, | ||
String email, | ||
OAuthProvider oAuthProvider, | ||
String oAuthProviderId | ||
) { | ||
return new OAuthInfoDto.Response( | ||
name, | ||
profileImage, | ||
birthYear, | ||
birthDay, | ||
email, | ||
oAuthProvider, | ||
oAuthProviderId | ||
); | ||
} | ||
} | ||
|
||
} |
34 changes: 0 additions & 34 deletions
34
src/main/java/coffeemeet/server/oauth/dto/OAuthInfoResponse.java
This file was deleted.
Oops, something went wrong.
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
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
13 changes: 13 additions & 0 deletions
13
src/test/java/coffeemeet/server/common/fixture/dto/KakaoMemberResponseFixture.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 coffeemeet.server.common.fixture.dto; | ||
|
||
import coffeemeet.server.oauth.infrastructure.kakao.dto.KakaoMemberResponse; | ||
import org.instancio.Instancio; | ||
|
||
public class KakaoMemberResponseFixture { | ||
|
||
public static KakaoMemberResponse kakaoMemberResponse() { | ||
return Instancio.of(KakaoMemberResponse.class) | ||
.create(); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/test/java/coffeemeet/server/common/fixture/dto/KakaoTokensFixture.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 coffeemeet.server.common.fixture.dto; | ||
|
||
import coffeemeet.server.oauth.infrastructure.kakao.dto.KakaoTokens; | ||
import org.instancio.Instancio; | ||
|
||
public class KakaoTokensFixture { | ||
|
||
public static KakaoTokens kakaoTokens() { | ||
return Instancio.of(KakaoTokens.class) | ||
.create(); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/test/java/coffeemeet/server/common/fixture/dto/OAuthInfoResponseFixture.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 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(); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/coffeemeet/server/oauth/authcode/AuthCodeRequestUrlProviderCompositeTest.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,49 @@ | ||
package coffeemeet.server.oauth.authcode; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
import coffeemeet.server.user.domain.OAuthProvider; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
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 AuthCodeRequestUrlProviderCompositeTest { | ||
|
||
@Mock | ||
private AuthCodeRequestUrlProvider provider; | ||
|
||
@Mock | ||
private Set<AuthCodeRequestUrlProvider> providers; | ||
|
||
@InjectMocks | ||
private AuthCodeRequestUrlProviderComposite composite; | ||
|
||
@DisplayName("sns 의 redirect url 을 제공할 수 있다.") | ||
@Test | ||
void provideTest() { | ||
// given | ||
OAuthProvider oAuthProvider = OAuthProvider.KAKAO; | ||
String resultUrl = "https://kakao.com/login/oauth/authorize?client_id=testClientId&redirect_uri=https://testClientId/redirect"; | ||
|
||
given(provider.oAuthProvider()).willReturn(OAuthProvider.KAKAO); | ||
given(provider.provide()).willReturn(resultUrl); | ||
|
||
providers = new HashSet<>(Collections.singletonList(provider)); | ||
composite = new AuthCodeRequestUrlProviderComposite(providers); | ||
|
||
// when | ||
String expectedUrl = composite.provide(oAuthProvider); | ||
|
||
// then | ||
assertThat(resultUrl).isEqualTo(expectedUrl); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/coffeemeet/server/oauth/client/OAuthMemberClientCompositeTest.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,52 @@ | ||
package coffeemeet.server.oauth.client; | ||
|
||
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.user.domain.OAuthProvider; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
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 OAuthMemberClientCompositeTest { | ||
|
||
@Mock | ||
private OAuthMemberClient client; | ||
|
||
@Mock | ||
private Set<OAuthMemberClient> clients; | ||
|
||
@InjectMocks | ||
private OAuthMemberClientComposite composite; | ||
|
||
@DisplayName("sns 로부터 사용자 정보를 가져올 수 있다.") | ||
@Test | ||
void fetchTest() { | ||
// given | ||
String authCode = "authCode"; | ||
OAuthProvider oAuthProvider = OAuthProvider.KAKAO; | ||
OAuthInfoDto.Response response = OAuthInfoResponseFixture.oAuthInfoResponse(); | ||
|
||
given(client.oAuthProvider()).willReturn(OAuthProvider.KAKAO); | ||
given(client.fetch(authCode)).willReturn(response); | ||
|
||
clients = new HashSet<>(Collections.singletonList(client)); | ||
composite = new OAuthMemberClientComposite(clients); | ||
|
||
// when | ||
OAuthInfoDto.Response expectedResponse = composite.fetch(oAuthProvider, authCode); | ||
|
||
// then | ||
assertThat(response).isEqualTo(expectedResponse); | ||
} | ||
|
||
} |
Oops, something went wrong.