31
31
import com .ajou .hertz .common .auth .JwtTokenProvider ;
32
32
import com .ajou .hertz .common .auth .UserPrincipal ;
33
33
import com .ajou .hertz .common .config .SecurityConfig ;
34
+ import com .ajou .hertz .common .file .dto .FileDto ;
34
35
import com .ajou .hertz .domain .user .constant .Gender ;
35
36
import com .ajou .hertz .domain .user .constant .RoleType ;
36
37
import com .ajou .hertz .domain .user .controller .UserController ;
37
38
import com .ajou .hertz .domain .user .dto .UserDto ;
38
39
import com .ajou .hertz .domain .user .dto .request .SignUpRequest ;
39
40
import com .ajou .hertz .domain .user .service .UserCommandService ;
41
+ import com .ajou .hertz .domain .user .service .UserProfileImageCommandService ;
40
42
import com .ajou .hertz .domain .user .service .UserQueryService ;
41
43
import com .ajou .hertz .util .ReflectionUtils ;
42
44
import com .fasterxml .jackson .databind .ObjectMapper ;
@@ -61,6 +63,9 @@ class UserControllerTest {
61
63
@ MockBean
62
64
private UserQueryService userQueryService ;
63
65
66
+ @ MockBean
67
+ private UserProfileImageCommandService userProfileImageCommandService ;
68
+
64
69
private final MockMvc mvc ;
65
70
66
71
private final ObjectMapper objectMapper ;
@@ -224,12 +229,16 @@ public void securitySetUp() throws Exception {
224
229
"test" .getBytes ()
225
230
);
226
231
UserDetails userDetails = createTestUser (userId );
232
+ FileDto uploadedFile = createFileDto ();
227
233
UserDto expectedResult = createUserDto (userId );
228
- given (userCommandService .updateProfileImageUrl (userId , profileImage )).willReturn (expectedResult );
234
+
235
+ given (userProfileImageCommandService .uploadProfileImage (userId , profileImage )).willReturn (
236
+ uploadedFile );
237
+ given (userCommandService .updateProfileImage (userId , uploadedFile )).willReturn (expectedResult );
229
238
230
239
// when & then
231
240
mvc .perform (
232
- multipart ("/api/users/me/profile-image " )
241
+ multipart ("/api/users/me/profile-images " )
233
242
.file (profileImage )
234
243
.header (API_VERSION_HEADER_NAME , 1 )
235
244
.with (user (userDetails ))
@@ -240,7 +249,8 @@ public void securitySetUp() throws Exception {
240
249
)
241
250
.andExpect (status ().isOk ())
242
251
.andExpect (jsonPath ("$.profileImageUrl" ).value (expectedResult .getProfileImageUrl ()));
243
- then (userCommandService ).should ().updateProfileImageUrl (userId , profileImage );
252
+ then (userProfileImageCommandService ).should ().uploadProfileImage (userId , profileImage );
253
+ then (userCommandService ).should ().updateProfileImage (userId , uploadedFile );
244
254
verifyEveryMocksShouldHaveNoMoreInteractions ();
245
255
}
246
256
@@ -270,6 +280,7 @@ public void securitySetUp() throws Exception {
270
280
private void verifyEveryMocksShouldHaveNoMoreInteractions () {
271
281
then (userCommandService ).shouldHaveNoMoreInteractions ();
272
282
then (userQueryService ).shouldHaveNoMoreInteractions ();
283
+ then (userProfileImageCommandService ).shouldHaveNoMoreInteractions ();
273
284
}
274
285
275
286
private SignUpRequest createSignUpRequest (String email , String password , String phone ) throws Exception {
@@ -314,4 +325,11 @@ private UserDetails createTestUser(Long userId) throws Exception {
314
325
return new UserPrincipal (createUserDto (userId ));
315
326
}
316
327
328
+ private FileDto createFileDto () throws Exception {
329
+ return ReflectionUtils .createFileDto (
330
+ "test.jpg" ,
331
+ "test-stored.jpg" ,
332
+ "https://example.com/user-profile-images/storedFileName.jpg" );
333
+ }
334
+
317
335
}
0 commit comments