-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/member info #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/member info #149
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| package com.und.server.member.controller; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.doThrow; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
@@ -28,6 +31,7 @@ | |
| import com.und.server.common.exception.ServerException; | ||
| import com.und.server.member.dto.request.NicknameRequest; | ||
| import com.und.server.member.dto.response.MemberResponse; | ||
| import com.und.server.member.entity.Member; | ||
| import com.und.server.member.service.MemberService; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
|
|
@@ -131,6 +135,59 @@ void Given_AuthenticatedUser_When_UpdateNickname_Then_ReturnsOkWithUpdatedInfo() | |
| .andExpect(jsonPath("$.nickname").value(newNickname)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Fails to get member and returns unauthorized when user is not authenticated") | ||
| void Given_UnauthenticatedUser_When_GetMember_Then_ReturnsUnauthorized() throws Exception { | ||
| // given | ||
| final String url = "/v1/member/nickname"; | ||
| final AuthErrorResult errorResult = AuthErrorResult.UNAUTHORIZED_ACCESS; | ||
|
|
||
| doReturn(true).when(authMemberArgumentResolver).supportsParameter(any()); | ||
| doThrow(new ServerException(errorResult)) | ||
| .when(authMemberArgumentResolver).resolveArgument(any(), any(), any(), any()); | ||
|
|
||
| // when | ||
| final ResultActions resultActions = mockMvc.perform( | ||
| MockMvcRequestBuilders.get(url) | ||
| ); | ||
|
|
||
| // then | ||
| resultActions.andExpect(status().isUnauthorized()) | ||
| .andExpect(jsonPath("$.code").value(errorResult.name())) | ||
| .andExpect(jsonPath("$.message").value(errorResult.getMessage())); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Succeeds in getting member nickname for an authenticated user") | ||
| void Given_AuthenticatedUser_When_GetMember_Then_ReturnsOkWithNickname() throws Exception { | ||
| // given | ||
| final String url = "/v1/member/nickname"; | ||
| final Long memberId = 1L; | ||
| final String nickname = "Chori"; | ||
| final Member member = Member.builder() | ||
| .id(memberId) | ||
| .nickname(nickname) | ||
| .build(); | ||
|
|
||
| doReturn(true).when(authMemberArgumentResolver).supportsParameter(any()); | ||
| doReturn(memberId).when(authMemberArgumentResolver).resolveArgument(any(), any(), any(), any()); | ||
| doReturn(member).when(memberService).findMemberById(memberId); | ||
|
|
||
| // when | ||
| final ResultActions resultActions = mockMvc.perform( | ||
| MockMvcRequestBuilders.get(url) | ||
| ); | ||
|
|
||
| // then | ||
| final String responseContent = resultActions | ||
| .andExpect(status().isOk()) | ||
| .andReturn() | ||
| .getResponse() | ||
| .getContentAsString(StandardCharsets.UTF_8); | ||
| assertThat(responseContent).isEqualTo(nickname); | ||
|
Comment on lines
+182
to
+187
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| verify(memberService).findMemberById(memberId); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Fails to delete member and returns unauthorized when user is not authenticated") | ||
| void Given_UnauthenticatedUser_When_DeleteMember_Then_ReturnsUnauthorized() throws Exception { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API 응답의 일관성과 확장성을 위해 원시 문자열(raw string) 대신 JSON 객체를 반환하는 것이 좋습니다. 다른 API(
updateNickname등)들이 JSON을 반환하는 것과 맞추면 클라이언트 측에서 더 일관되게 처리할 수 있습니다.java.util.Map을 사용하여 간단한 JSON 객체를 생성할 수 있습니다. 아래 제안처럼 FQCN(정규화된 클래스 이름)을 사용하면 별도의 import문 추가 없이 바로 적용 가능하며, 추후 import문을 추가하고 타입을 간소화할 수 있습니다.또한
ResponseEntity.status(HttpStatus.OK).body(...)대신ResponseEntity.ok(...)을 사용하면 코드를 더 간결하게 만들 수 있습니다.