diff --git a/src/test/java/toy/bookchat/bookchat/domain/user/api/UserControllerTest.java b/src/test/java/toy/bookchat/bookchat/domain/user/api/UserControllerTest.java index c4fea2eb..c2aee9ad 100644 --- a/src/test/java/toy/bookchat/bookchat/domain/user/api/UserControllerTest.java +++ b/src/test/java/toy/bookchat/bookchat/domain/user/api/UserControllerTest.java @@ -55,6 +55,7 @@ import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -64,13 +65,12 @@ import org.springframework.util.Base64Utils; import toy.bookchat.bookchat.db_module.user.UserEntity; import toy.bookchat.bookchat.domain.ControllerTestExtension; -import toy.bookchat.bookchat.domain.user.UserProfile; +import toy.bookchat.bookchat.domain.user.User; import toy.bookchat.bookchat.domain.user.api.v1.request.ChangeUserNicknameRequest; import toy.bookchat.bookchat.domain.user.api.v1.request.UserSignInRequest; import toy.bookchat.bookchat.domain.user.api.v1.request.UserSignUpRequest; import toy.bookchat.bookchat.domain.user.api.v1.response.MemberProfileResponse; import toy.bookchat.bookchat.domain.user.api.v1.response.Token; -import toy.bookchat.bookchat.domain.user.api.v1.response.UserProfileResponse; import toy.bookchat.bookchat.domain.user.service.UserService; import toy.bookchat.bookchat.exception.conflict.device.DeviceAlreadyRegisteredException; import toy.bookchat.bookchat.exception.unauthorized.ExpiredTokenException; @@ -122,20 +122,20 @@ public void init() throws FileNotFoundException { } @Test - void 사용자_프로필_정보_반환() throws Exception { + @DisplayName("사용자 프로필 정보 반환") + void userProfile() throws Exception { UserEntity userEntity = getUser(); - UserProfile userProfile = UserProfile.from(userEntity); - - String real = objectMapper.writeValueAsString(UserProfileResponse.builder() - .userId(userEntity.getId()) - .userEmail(userEntity.getEmail()) - .userNickname(userEntity.getNickname()) - .userProfileImageUri(userEntity.getProfileImageUrl()) + User user = User.builder() + .id(userEntity.getId()) + .email(userEntity.getEmail()) + .nickname(userEntity.getNickname()) + .profileImageUrl(userEntity.getProfileImageUrl()) .defaultProfileImageType(userEntity.getDefaultProfileImageType()) - .build()); - given(userService.findUser(any())).willReturn(userProfile); + .build(); - MvcResult mvcResult = mockMvc.perform(get("/v1/api/users/profile") + given(userService.findUser(any())).willReturn(user); + + mockMvc.perform(get("/v1/api/users/profile") .with(user(getUserPrincipal())) .header(AUTHORIZATION, JWT_TOKEN)) .andExpect(status().isOk()) @@ -149,10 +149,7 @@ public void init() throws FileNotFoundException { fieldWithPath("userEmail").type(STRING).description("이메일"), fieldWithPath("userProfileImageUri").type(STRING).description("프로필 사진 URI"), fieldWithPath("defaultProfileImageType").type(NUMBER).description("기본 이미지 타입") - ))) - .andReturn(); - - assertThat(mvcResult.getResponse().getContentAsString()).isEqualTo(real); + ))); } @Test diff --git a/src/test/java/toy/bookchat/bookchat/domain/user/service/UserServiceTest.java b/src/test/java/toy/bookchat/bookchat/domain/user/service/UserServiceTest.java index c4f4e4a9..cfc65b6b 100644 --- a/src/test/java/toy/bookchat/bookchat/domain/user/service/UserServiceTest.java +++ b/src/test/java/toy/bookchat/bookchat/domain/user/service/UserServiceTest.java @@ -24,9 +24,6 @@ import toy.bookchat.bookchat.db_module.device.repository.DeviceRepository; import toy.bookchat.bookchat.db_module.user.UserEntity; import toy.bookchat.bookchat.db_module.user.repository.UserRepository; -import toy.bookchat.bookchat.support.Status; -import toy.bookchat.bookchat.infrastructure.s3.StorageService; -import toy.bookchat.bookchat.domain.user.UserProfile; import toy.bookchat.bookchat.domain.user.api.v1.request.ChangeUserNicknameRequest; import toy.bookchat.bookchat.domain.user.api.v1.request.UserSignInRequest; import toy.bookchat.bookchat.domain.user.api.v1.request.UserSignUpRequest; @@ -34,6 +31,8 @@ import toy.bookchat.bookchat.exception.badrequest.user.UserAlreadySignUpException; import toy.bookchat.bookchat.exception.conflict.device.DeviceAlreadyRegisteredException; import toy.bookchat.bookchat.infrastructure.fcm.service.PushService; +import toy.bookchat.bookchat.infrastructure.s3.StorageService; +import toy.bookchat.bookchat.support.Status; @ExtendWith(MockitoExtension.class) class UserServiceTest { @@ -230,18 +229,10 @@ void deleteDevice() throws Exception { } @Test - void 사용자_프로필_조회_성공() throws Exception { - UserEntity userEntity = UserEntity.builder() - .id(1L) - .nickname("user1") - .email("kKvTABYqa@test.com") - .profileImageUrl("profile-image-url") - .defaultProfileImageType(2) - .build(); - given(userReader.readUserEntity(anyLong())).willReturn(userEntity); - - UserProfile userProfile = userService.findUser(1L); + @DisplayName("사용자 프로필 조회 성공") + void findUser() throws Exception { + userService.findUser(1L); - verify(userReader).readUserEntity(anyLong()); + verify(userReader).readUser(any()); } } \ No newline at end of file