Skip to content

Commit

Permalink
feat: 다른 유저 정보 조회 구현 (#59)
Browse files Browse the repository at this point in the history
* feat: 다른 유저 정보 조회 api 생성

* test: 다른 유저 정보 조회 api 테스트
  • Loading branch information
redcarrot1 authored Aug 16, 2023
1 parent 656aee5 commit 8476876
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ResponseEntity<SignupResponse> signup(@RequestBody @Valid SignupRequest r
}

@GetMapping
public ResponseEntity<UserInformationResponse> getUserInformation(@LoginUserId Long loginUserId) {
public ResponseEntity<UserInformationResponse> getMyInformation(@LoginUserId Long loginUserId) {
UserInformationResponse response = userInformationService.getUserInformation(loginUserId);
return ResponseEntity.ok(response);
}
Expand All @@ -65,4 +65,10 @@ public ResponseEntity<Void> updateUserInformation(@LoginUserId Long loginUserId,
userInformationService.updateInformation(loginUserId, request.getNickname(), request.getProfileImageURL());
return ResponseEntity.ok().build();
}

@GetMapping("{userId}")
public ResponseEntity<UserInformationResponse> getUserInformation(@PathVariable Long userId) {
UserInformationResponse response = userInformationService.getUserInformation(userId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class UserControllerTest {
@Autowired
private TokenManager tokenManager;

private static Long userId = 1L;

@Test
@DisplayName("임시 토큰 발급")
void getTemporaryToken() throws Exception {
Expand Down Expand Up @@ -272,8 +274,8 @@ void signupFailByExitUser() throws Exception {
}

@Test
@DisplayName("회원정보 조회")
void getUserInformation() throws Exception {
@DisplayName("내 정보 조회")
void getMyInformation() throws Exception {
// given
User savedUser = saveTestUser();
TokenDto tokenDto = tokenManager.createTokenDto(savedUser.getId());
Expand All @@ -290,6 +292,26 @@ void getUserInformation() throws Exception {
.andDo(print());
}

@Test
@DisplayName("다른 회원정보 조회")
void getUserInformation() throws Exception {
// given
User savedUser = saveTestUser();
TokenDto tokenDto = tokenManager.createTokenDto(savedUser.getId());
User requestUser = saveTestUser();

// when
mockMvc.perform(get("/api/users/" + requestUser.getId())
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + tokenDto.getAccessToken()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.nickname").value(requestUser.getNickname()))
.andExpect(jsonPath("$.profileImageURL").value(requestUser.getProfileImageURL()))
.andExpect(jsonPath("$.oAuthProvider").value(requestUser.getOAuthProvider().name()))
.andExpect(jsonPath("$.id").value(requestUser.getId()))
.andDo(print());
}

@Test
@DisplayName("회원정보 수정 성공")
void updateInformationSuccess() throws Exception {
Expand Down Expand Up @@ -344,11 +366,12 @@ void updateInformationFailByDuplicatedNickname() throws Exception {

private User saveTestUser() {
User user = User.builder()
.oAuthId("12345678")
.oAuthId("12345678" + userId)
.oAuthProvider(OAuthProvider.KAKAO)
.nickname("nickname")
.profileImageURL("profileImageURL")
.nickname("nickname" + userId)
.profileImageURL("profileImageURL" + userId)
.build();
userId += 1;
return userRepository.save(user);
}
}

0 comments on commit 8476876

Please sign in to comment.