Skip to content

Commit 688d832

Browse files
committed
Merge branch 'dev'
2 parents dd2eb1b + 524a129 commit 688d832

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

backend/src/test/java/com/deliveranything/domain/user/profile/service/ProfileServiceTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class CreateProfileTest {
7575
void createProfile_first_customer_success() {
7676
User mockUser = mock(User.class);
7777
when(mockUser.getId()).thenReturn(1L);
78-
when(mockUser.hasActiveProfile()).thenReturn(false);
7978

8079
when(profileRepository.existsByUserIdAndType(1L, ProfileType.CUSTOMER)).thenReturn(false);
8180

@@ -104,7 +103,6 @@ void createProfile_first_customer_success() {
104103
void createProfile_additional_seller_success() {
105104
User mockUser = mock(User.class);
106105
when(mockUser.getId()).thenReturn(1L);
107-
when(mockUser.hasActiveProfile()).thenReturn(true);
108106

109107
when(profileRepository.existsByUserIdAndType(1L, ProfileType.SELLER)).thenReturn(false);
110108
when(sellerProfileRepository.existsByBusinessCertificateNumber(anyString()))
@@ -127,16 +125,15 @@ void createProfile_additional_seller_success() {
127125
assertNotNull(result);
128126
verify(profileRepository, times(1)).save(any(Profile.class));
129127
verify(sellerProfileRepository, times(1)).save(any(SellerProfile.class));
130-
verify(mockUser, never()).setCurrentActiveProfile(any());
131-
verify(userRepository, never()).save(any());
128+
verify(mockUser, times(1)).setCurrentActiveProfile(any(Profile.class));
129+
verify(userRepository, times(1)).save(mockUser);
132130
}
133131

134132
@Test
135133
@DisplayName("성공 - 라이더 프로필 생성")
136134
void createProfile_rider_success() {
137135
User mockUser = mock(User.class);
138136
when(mockUser.getId()).thenReturn(1L);
139-
when(mockUser.hasActiveProfile()).thenReturn(false);
140137

141138
when(profileRepository.existsByUserIdAndType(1L, ProfileType.RIDER)).thenReturn(false);
142139

@@ -156,6 +153,10 @@ void createProfile_rider_success() {
156153
assertNotNull(result);
157154
verify(profileRepository, times(1)).save(any(Profile.class));
158155
verify(riderProfileRepository, times(1)).save(any(RiderProfile.class));
156+
verify(mockUser, times(1)).setCurrentActiveProfile(any(Profile.class));
157+
verify(userRepository, times(1)).save(mockUser);
158+
verify(mockUser, times(1)).setCurrentActiveProfile(any(Profile.class));
159+
verify(userRepository, times(1)).save(mockUser);
159160
}
160161

161162
@Test

backend/src/test/java/com/deliveranything/domain/user/user/controller/UserControllerTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
import static org.mockito.ArgumentMatchers.any;
7+
import static org.mockito.ArgumentMatchers.eq;
68
import static org.mockito.Mockito.doNothing;
79
import static org.mockito.Mockito.mock;
810
import static org.mockito.Mockito.times;
@@ -35,6 +37,8 @@
3537
import org.mockito.InjectMocks;
3638
import org.mockito.Mock;
3739
import org.mockito.junit.jupiter.MockitoExtension;
40+
import org.mockito.junit.jupiter.MockitoSettings;
41+
import org.mockito.quality.Strictness;
3842
import org.springframework.http.HttpStatus;
3943
import org.springframework.http.ResponseEntity;
4044

@@ -140,6 +144,7 @@ void changePassword_success() {
140144
@DisplayName("프로필 생성 테스트")
141145
class CreateProfileTest {
142146

147+
@MockitoSettings(strictness = Strictness.LENIENT)
143148
@Test
144149
@DisplayName("성공 - 프로필 생성")
145150
void createProfile_success() {
@@ -150,16 +155,31 @@ void createProfile_success() {
150155
Profile mockProfile = mock(Profile.class);
151156
when(mockProfile.getId()).thenReturn(10L);
152157
when(mockProfile.isActive()).thenReturn(true);
158+
when(mockProfile.getType()).thenReturn(ProfileType.CUSTOMER);
159+
when(mockProfile.getUser()).thenReturn(mockUser);
160+
when(mockProfile.getType()).thenReturn(ProfileType.CUSTOMER);
153161

154162
CustomerProfileCreateData profileData = new CustomerProfileCreateData(
155163
"닉네임", null, "01012345678"
156164
);
157165

158166
CreateProfileRequest request = new CreateProfileRequest(ProfileType.CUSTOMER, profileData);
159167

160-
when(profileService.createProfile(mockUser, ProfileType.CUSTOMER, profileData))
168+
when(profileService.createProfile(eq(mockUser), eq(ProfileType.CUSTOMER), any()))
161169
.thenReturn(mockProfile);
162170

171+
when(rq.getDeviceId()).thenReturn("device123");
172+
when(rq.getAccessTokenFromHeader()).thenReturn("oldAccessToken");
173+
174+
SwitchProfileResult switchResult = new SwitchProfileResult(
175+
SwitchProfileResponse.builder().build(),
176+
"newAccessToken"
177+
);
178+
179+
when(authService.switchProfileWithTokenReissue(
180+
any(Long.class), any(ProfileType.class), any(String.class), any(String.class)
181+
)).thenReturn(switchResult);
182+
163183
ResponseEntity<ApiResponse<CreateProfileResponse>> response = userController.createProfile(
164184
request);
165185

0 commit comments

Comments
 (0)