1+ package com .somemore .user .service ;
2+
3+ import com .somemore .global .auth .oauth .domain .CommonOAuthInfo ;
4+ import com .somemore .global .auth .oauth .domain .OAuthProvider ;
5+ import com .somemore .global .imageupload .service .ImageUploadService ;
6+ import com .somemore .support .IntegrationTestSupport ;
7+ import com .somemore .user .domain .User ;
8+ import com .somemore .user .domain .UserCommonAttribute ;
9+ import com .somemore .user .domain .UserRole ;
10+ import com .somemore .user .domain .UserSetting ;
11+ import com .somemore .user .dto .UserAuthInfo ;
12+ import com .somemore .user .repository .user .UserRepository ;
13+ import com .somemore .user .repository .usercommonattribute .UserCommonAttributeRepository ;
14+ import com .somemore .user .repository .usersetting .UserSettingRepository ;
15+ import org .junit .jupiter .api .BeforeEach ;
16+ import org .junit .jupiter .api .DisplayName ;
17+ import org .junit .jupiter .api .Test ;
18+ import org .springframework .beans .factory .annotation .Autowired ;
19+ import org .springframework .transaction .annotation .Transactional ;
20+
21+ import java .util .UUID ;
22+
23+ import static org .assertj .core .api .Assertions .assertThat ;
24+
25+ @ Transactional
26+ class RegisterUserServiceTest extends IntegrationTestSupport {
27+
28+ @ Autowired
29+ private RegisterUserService registerUserService ;
30+
31+ @ Autowired
32+ private UserRepository userRepository ;
33+
34+ @ Autowired
35+ private UserSettingRepository userSettingRepository ;
36+
37+ @ Autowired
38+ private UserCommonAttributeRepository userCommonAttributeRepository ;
39+
40+ @ BeforeEach
41+ void setup () {
42+ }
43+
44+ @ DisplayName ("OAuth 사용자를 기본 ROLE인 봉사자로 등록할 수 있다." )
45+ @ Test
46+ void registerOAuthUser () {
47+ // given
48+ OAuthProvider provider = OAuthProvider .NAVER ;
49+ CommonOAuthInfo commonOAuthInfo = new CommonOAuthInfo (provider , "test" );
50+
51+ // when
52+ User registeredUser = registerUserService .registerOAuthUser (commonOAuthInfo , UserRole .getOAuthUserDefaultRole ());
53+
54+ // then
55+ User savedUser = userRepository .findById (registeredUser .getId ()).orElseThrow ();
56+ UserSetting savedSetting = userSettingRepository .findByUserId (registeredUser .getId ()).orElseThrow ();
57+ UserCommonAttribute savedCommonAttribute = userCommonAttributeRepository .findByUserId (registeredUser .getId ()).orElseThrow ();
58+
59+ assertThat (savedUser ).isNotNull ();
60+ assertThat (savedUser .getRole ()).isEqualTo (UserRole .getOAuthUserDefaultRole ());
61+ assertThat (savedUser .getEmail ().length ()).isEqualTo (UUID .randomUUID ().toString ().length () + provider .getProviderName ().length ());
62+
63+ assertThat (savedSetting ).isNotNull ();
64+ assertThat (savedSetting .getUserId ()).isEqualTo (savedUser .getId ());
65+ boolean userDefaultSetting = false ;
66+ assertThat (savedSetting .isSmsAgreed ()).isEqualTo (userDefaultSetting );
67+ assertThat (savedSetting .isAuthenticated ()).isEqualTo (userDefaultSetting );
68+
69+ assertThat (savedCommonAttribute ).isNotNull ();
70+ assertThat (savedCommonAttribute .getUserId ()).isEqualTo (savedUser .getId ());
71+ assertThat (savedCommonAttribute .getNickname ().length ()).isEqualTo (8 );
72+ assertThat (savedCommonAttribute .getIntroduce ()).isEqualTo ("" );
73+ assertThat (savedCommonAttribute .getImgUrl ()).isEqualTo (ImageUploadService .DEFAULT_IMAGE_URL );
74+ assertThat (savedCommonAttribute .isCustomized ()).isEqualTo (userDefaultSetting );
75+
76+ }
77+
78+ @ DisplayName ("로컬 사용자를 등록할 수 있다." )
79+ @ Test
80+ void registerLocalUser () {
81+ // given
82+ UserAuthInfo userAuthInfo = new UserAuthInfo ("test" , "test" );
83+ UserRole role = UserRole .CENTER ;
84+
85+ // when
86+ User registeredUser = registerUserService .registerLocalUser (userAuthInfo , role );
87+
88+ // then
89+ User savedUser = userRepository .findById (registeredUser .getId ()).orElseThrow ();
90+ UserSetting savedSetting = userSettingRepository .findByUserId (registeredUser .getId ()).orElseThrow ();
91+ UserCommonAttribute savedCommonAttribute = userCommonAttributeRepository .findByUserId (registeredUser .getId ()).orElseThrow ();
92+
93+ assertThat (savedUser ).isNotNull ();
94+ assertThat (savedUser .getRole ()).isEqualTo (role );
95+ assertThat (savedUser .getEmail ()).isEqualTo ("test" );
96+
97+ assertThat (savedSetting ).isNotNull ();
98+ assertThat (savedSetting .getUserId ()).isEqualTo (savedUser .getId ());
99+ boolean userDefaultSetting = false ;
100+ assertThat (savedSetting .isSmsAgreed ()).isEqualTo (userDefaultSetting );
101+ assertThat (savedSetting .isAuthenticated ()).isEqualTo (userDefaultSetting );
102+
103+ assertThat (savedCommonAttribute ).isNotNull ();
104+ assertThat (savedCommonAttribute .getUserId ()).isEqualTo (savedUser .getId ());
105+ assertThat (savedCommonAttribute .getNickname ().length ()).isEqualTo (8 );
106+ assertThat (savedCommonAttribute .getIntroduce ()).isEqualTo ("" );
107+ assertThat (savedCommonAttribute .getImgUrl ()).isEqualTo (ImageUploadService .DEFAULT_IMAGE_URL );
108+ assertThat (savedCommonAttribute .isCustomized ()).isEqualTo (userDefaultSetting );
109+ }
110+ }
0 commit comments