|
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
4 | 4 | import static org.junit.jupiter.api.Assertions.assertAll; |
5 | | -import static org.mockito.ArgumentMatchers.anyString; |
6 | | -import static org.mockito.Mockito.doReturn; |
7 | 5 |
|
8 | 6 | import eatda.client.oauth.OauthMemberInformation; |
9 | | -import eatda.client.oauth.OauthToken; |
10 | | -import eatda.controller.auth.LoginRequest; |
11 | 7 | import eatda.controller.member.MemberResponse; |
12 | 8 | import eatda.service.BaseServiceTest; |
13 | | -import java.net.URI; |
14 | | -import java.net.URISyntaxException; |
15 | | -import org.junit.jupiter.api.BeforeEach; |
16 | 9 | import org.junit.jupiter.api.Nested; |
17 | 10 | import org.junit.jupiter.api.Test; |
18 | | -import org.springframework.beans.factory.annotation.Autowired; |
19 | 11 |
|
20 | 12 | class AuthServiceTest extends BaseServiceTest { |
21 | 13 |
|
22 | | - private static final OauthToken DEFAULT_OAUTH_TOKEN = new OauthToken("oauth-access-token"); |
23 | | - private static final OauthMemberInformation DEFAULT_OAUTH_MEMBER_INFO = |
24 | | - new OauthMemberInformation( 123L, "[email protected]", "nickname"); |
25 | | - |
26 | | - @Autowired |
27 | | - private AuthService authService; |
28 | | - |
29 | | - @BeforeEach |
30 | | - protected final void mockingClient() throws URISyntaxException { |
31 | | - doReturn(new URI("http://localhost:8080/login/callback")).when(oauthClient).getOauthLoginUrl(anyString()); |
32 | | - doReturn(DEFAULT_OAUTH_TOKEN).when(oauthClient).requestOauthToken(anyString(), anyString()); |
33 | | - doReturn(DEFAULT_OAUTH_MEMBER_INFO).when(oauthClient).requestMemberInformation(DEFAULT_OAUTH_TOKEN); |
34 | | - } |
35 | | - |
36 | 14 | @Nested |
37 | 15 | class Login { |
38 | 16 |
|
39 | 17 | @Test |
40 | 18 | void 로그인_최초_요청_시_회원가입_및_로그인_처리를_한다() { |
41 | | - LoginRequest request = new LoginRequest("auth_code", "http://localhost:3000"); |
| 19 | + OauthMemberInformation oauthInformation = new OauthMemberInformation(123L, "[email protected]", "nickname"); |
42 | 20 |
|
43 | | - MemberResponse response = authService.login(request); |
| 21 | + MemberResponse response = authService.login(oauthInformation); |
44 | 22 |
|
45 | 23 | assertAll( |
46 | 24 | () -> assertThat(response.isSignUp()).isTrue(), |
47 | | - () -> assertThat(response.nickname()).isNotNull(), |
48 | | - () -> assertThat(response.phoneNumber()).isNull(), |
49 | | - () -> assertThat(response.optInMarketing()).isNull() |
| 25 | + () -> assertThat(response.id()).isNotZero(), |
| 26 | + () -> assertThat( response. email()). isEqualTo("[email protected]"), |
| 27 | + () -> assertThat(response.nickname()).isEqualTo("nickname") |
50 | 28 | ); |
51 | 29 | } |
52 | 30 |
|
53 | 31 | @Test |
54 | 32 | void 로그인_최초_요청이_아닐_경우_로그인만_처리를_한다() { |
55 | 33 | memberGenerator.generate("123"); |
56 | | - LoginRequest request = new LoginRequest("auth_code", "http://localhost:3000"); |
| 34 | + OauthMemberInformation oauthInformation = new OauthMemberInformation(123L, "[email protected]", "nickname"); |
57 | 35 |
|
58 | | - MemberResponse response = authService.login(request); |
| 36 | + MemberResponse response = authService.login(oauthInformation); |
59 | 37 |
|
60 | 38 | assertThat(response.isSignUp()).isFalse(); |
61 | 39 | } |
|
0 commit comments