-
Notifications
You must be signed in to change notification settings - Fork 1
π¨ Modify api endpoint #150
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
| verify(memberService).findMemberById(memberId); | ||
|
Comment on lines
+181
to
+188
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. 컨νΈλ‘€λ¬ λ³κ²½ μ μμ λ§μΆ° ν
μ€νΈ μ½λλ μμ μ΄ νμν©λλ€. // then
resultActions.andExpect(status().isOk())
.andExpect(jsonPath("$.nickname").value(nickname));
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 { | ||
|
|
||
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) λ¬Έμμ΄μ λ°ννλ κ²λ³΄λ€ JSON κ°μ²΄λ₯Ό λ°ννλ κ²μ΄ μ’μ΅λλ€. μ΄λ APIμ μΌκ΄μ±μ μ μ§νκ³ ν₯ν νμ₯μ μ©μ΄νκ² ν©λλ€. μλ₯Ό λ€μ΄, λμ€μ λ€λ₯Έ νλλ₯Ό μΆκ°ν΄μΌ ν κ²½μ° ν΄λΌμ΄μΈνΈ μ½λ μμ μμ΄ μ½κ² νμ₯ν μ μμ΅λλ€.
Map.of()λ₯Ό μ¬μ©νκ±°λ μ μ© μλ΅ DTO(Data Transfer Object)λ₯Ό μμ±νμ¬ JSON κ°μ²΄λ‘ λλ€μμ λ°ννλλ‘ μμ νλ κ²μ μ μν©λλ€.ResponseEntity.ok()λ₯Ό μ¬μ©νλ©΄ μ½λλ₯Ό λ κ°κ²°νκ² λ§λ€ μ μμ΅λλ€.μ°Έκ³ : μλ μ μμ μ μ©νλ €λ©΄
import java.util.Map;ꡬ문μ μΆκ°ν΄μΌ ν©λλ€.μμ DTO: