Skip to content

Commit

Permalink
test: 사용자 프로필 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
geneaky committed Sep 18, 2024
1 parent c23b596 commit 525d43d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@
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;
import toy.bookchat.bookchat.domain.user.api.v1.response.MemberProfileResponse;
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 {
Expand Down Expand Up @@ -230,18 +229,10 @@ void deleteDevice() throws Exception {
}

@Test
void 사용자_프로필_조회_성공() throws Exception {
UserEntity userEntity = UserEntity.builder()
.id(1L)
.nickname("user1")
.email("[email protected]")
.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());
}
}

0 comments on commit 525d43d

Please sign in to comment.