Skip to content

Commit a4c38b0

Browse files
committed
[TEST] GetSocialAccountUsecase 구현체 테스트
<TODO> - 현재 Jwt Test 설정 및 리소스 파일 인식 과정에서의 Jwt Encoder Bean 생성 오류로 인해 일시적으로 local profile로 local property 소스를 활용하도록 했습니다. - 추후 오류 해결에 따른 test profile 반영이 필요합니다.
1 parent 67ad88e commit a4c38b0

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package sopt.makers.authentication.usecase.auth.service;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
import static org.mockito.BDDMockito.given;
6+
import static org.mockito.Mockito.mock;
7+
import static org.mockito.Mockito.when;
8+
9+
import sopt.makers.authentication.domain.auth.AuthPlatform;
10+
import sopt.makers.authentication.domain.auth.SocialAccount;
11+
import sopt.makers.authentication.domain.user.User;
12+
import sopt.makers.authentication.usecase.auth.port.in.GetSocialAccountUsecase;
13+
import sopt.makers.authentication.usecase.auth.port.out.UserRepository;
14+
15+
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Test;
17+
import org.springframework.beans.factory.annotation.Autowired;
18+
import org.springframework.boot.test.context.SpringBootTest;
19+
import org.springframework.boot.test.mock.mockito.MockBean;
20+
import org.springframework.test.context.ActiveProfiles;
21+
import org.springframework.test.context.TestPropertySource;
22+
23+
@SpringBootTest
24+
@ActiveProfiles("local")
25+
@TestPropertySource(locations = {"classpath:env/local.env"})
26+
class GetSocialAccountPlatformServiceTest {
27+
private static final String TEST_AUTH_ID = "test";
28+
private static final String TEST_USER_PHONE_FOR_GOOGLE = "01012345678";
29+
private static final String TEST_USER_PHONE_FOR_APPLE = "01087654321";
30+
31+
@MockBean UserRepository userRepository;
32+
33+
@Autowired GetSocialAccountPlatformService getSocialAccountPlatformService;
34+
35+
@BeforeEach
36+
void setMockUser() {
37+
User mockedUserForGoogle = mock(User.class);
38+
User mockedUserForApple = mock(User.class);
39+
SocialAccount mockedSocialAccountForGoogle = mock(SocialAccount.class);
40+
SocialAccount mockedSocialAccountForApple = mock(SocialAccount.class);
41+
42+
given(mockedSocialAccountForGoogle.authPlatformId()).willReturn(TEST_AUTH_ID);
43+
given(mockedSocialAccountForApple.authPlatformId()).willReturn(TEST_AUTH_ID);
44+
given(mockedSocialAccountForGoogle.authPlatformType()).willReturn(AuthPlatform.GOOGLE);
45+
given(mockedSocialAccountForApple.authPlatformType()).willReturn(AuthPlatform.APPLE);
46+
47+
given(mockedUserForGoogle.getSocialAccount()).willReturn(mockedSocialAccountForGoogle);
48+
given(mockedUserForApple.getSocialAccount()).willReturn(mockedSocialAccountForApple);
49+
50+
when(userRepository.findByPhone(TEST_USER_PHONE_FOR_GOOGLE)).thenReturn(mockedUserForGoogle);
51+
when(userRepository.findByPhone(TEST_USER_PHONE_FOR_APPLE)).thenReturn(mockedUserForApple);
52+
}
53+
54+
@Test
55+
void 주어진_Command에_대해_의도한_결과값을_반환한다() {
56+
// given
57+
GetSocialAccountUsecase.GetSocialAccountPlatformCommand givenCommandForGoogle =
58+
new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(
59+
null, TEST_USER_PHONE_FOR_GOOGLE);
60+
GetSocialAccountUsecase.GetSocialAccountPlatformCommand givenCommandForApple =
61+
new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(
62+
null, TEST_USER_PHONE_FOR_APPLE);
63+
64+
// when
65+
GetSocialAccountUsecase.SocialAccountPlatformInfo resultForGoogle =
66+
getSocialAccountPlatformService.getSocialAccountPlatform(givenCommandForGoogle);
67+
GetSocialAccountUsecase.SocialAccountPlatformInfo resultForApple =
68+
getSocialAccountPlatformService.getSocialAccountPlatform(givenCommandForApple);
69+
70+
// then
71+
assertThat(resultForGoogle.platformName()).isEqualTo("GOOGLE");
72+
assertThat(resultForApple.platformName()).isEqualTo("APPLE");
73+
}
74+
}

0 commit comments

Comments
 (0)