-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Upjuyanolja/feature/member-get
feat: 회원 정보 조회 기능 구현
- Loading branch information
Showing
7 changed files
with
240 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/backoffice/upjuyanolja/domain/member/dto/response/MemberInfoResponse.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.backoffice.upjuyanolja.domain.member.dto.response; | ||
|
||
import com.backoffice.upjuyanolja.domain.member.entity.Member; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record MemberInfoResponse( | ||
long memberId, | ||
String email, | ||
String name, | ||
String phoneNumber | ||
) { | ||
|
||
public static MemberInfoResponse of(Member member) { | ||
return MemberInfoResponse.builder() | ||
.memberId(member.getId()) | ||
.email(member.getEmail()) | ||
.name(member.getName()) | ||
.phoneNumber(member.getPhone()) | ||
.build(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/backoffice/upjuyanolja/domain/member/service/MemberGetService.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.backoffice.upjuyanolja.domain.member.service; | ||
|
||
import com.backoffice.upjuyanolja.domain.member.dto.response.MemberInfoResponse; | ||
import com.backoffice.upjuyanolja.domain.member.entity.Member; | ||
import com.backoffice.upjuyanolja.domain.member.exception.MemberNotFoundException; | ||
import com.backoffice.upjuyanolja.domain.member.repository.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MemberGetService { | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
public MemberInfoResponse getMember(long memberId) { | ||
return MemberInfoResponse.of(getMemberById(memberId)); | ||
} | ||
|
||
public Member getMemberById(long memberId) { | ||
return memberRepository.findById(memberId).orElseThrow(MemberNotFoundException::new); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -2,14 +2,17 @@ | |
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; | ||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; | ||
import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
|
||
import com.backoffice.upjuyanolja.domain.member.dto.response.CheckEmailDuplicateResponse; | ||
import com.backoffice.upjuyanolja.domain.member.dto.response.MemberInfoResponse; | ||
import com.backoffice.upjuyanolja.domain.member.service.MemberGetService; | ||
import com.backoffice.upjuyanolja.domain.member.service.MemberRegisterService; | ||
import com.backoffice.upjuyanolja.global.util.RestDocsSupport; | ||
import org.junit.jupiter.api.DisplayName; | ||
|
@@ -22,6 +25,9 @@ public class MemberControllerDocsTest extends RestDocsSupport { | |
@MockBean | ||
private MemberRegisterService memberRegisterService; | ||
|
||
@MockBean | ||
private MemberGetService memberGetService; | ||
|
||
@Test | ||
@DisplayName("checkEmailDuplicate()는 이메일 중복 검사를 할 수 있다.") | ||
void checkEmailDuplicate() throws Exception { | ||
|
@@ -41,8 +47,41 @@ void checkEmailDuplicate() throws Exception { | |
parameterWithName("email").description("이메일") | ||
), | ||
responseFields(successResponseCommon()).and( | ||
fieldWithPath("data.isExists").type(JsonFieldType.BOOLEAN).description("이메일 중복 여부") | ||
fieldWithPath("data.isExists").type(JsonFieldType.BOOLEAN) | ||
.description("이메일 중복 여부") | ||
) | ||
)); | ||
} | ||
} | ||
|
||
@Test | ||
@DisplayName("getMember()는 회원 정보를 조회할 수 있다.") | ||
void getMember() throws Exception { | ||
// given | ||
MemberInfoResponse memberInfoResponse = MemberInfoResponse.builder() | ||
.memberId(1L) | ||
.email("[email protected]") | ||
.name("test") | ||
.phoneNumber("010-1234-1234") | ||
.build(); | ||
|
||
given(memberGetService.getMember(any(Long.TYPE))) | ||
.willReturn(memberInfoResponse); | ||
|
||
// when then | ||
mockMvc.perform(get("/api/members/{memberId}", 1L)) | ||
.andDo(restDoc.document( | ||
responseFields(successResponseCommon()).and( | ||
fieldWithPath("data.memberId").type(JsonFieldType.NUMBER) | ||
.description("회원 식별자"), | ||
fieldWithPath("data.email").type(JsonFieldType.STRING) | ||
.description("이메일"), | ||
fieldWithPath("data.name").type(JsonFieldType.STRING) | ||
.description("이름"), | ||
fieldWithPath("data.phoneNumber").type(JsonFieldType.STRING) | ||
.description("전화번호") | ||
) | ||
)); | ||
|
||
verify(memberGetService, times(1)).getMember(any(Long.TYPE)); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
import com.backoffice.upjuyanolja.domain.member.controller.MemberController; | ||
import com.backoffice.upjuyanolja.domain.member.dto.response.CheckEmailDuplicateResponse; | ||
import com.backoffice.upjuyanolja.domain.member.dto.response.MemberInfoResponse; | ||
import com.backoffice.upjuyanolja.domain.member.service.MemberGetService; | ||
import com.backoffice.upjuyanolja.domain.member.service.MemberRegisterService; | ||
import com.backoffice.upjuyanolja.global.security.AuthenticationConfig; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
@@ -42,6 +44,9 @@ public class MemberControllerTest { | |
@MockBean | ||
private MemberRegisterService memberRegisterService; | ||
|
||
@MockBean | ||
private MemberGetService memberGetService; | ||
|
||
@Nested | ||
@DisplayName("checkEmailDuplicate()는") | ||
class Context_createComment { | ||
|
@@ -92,4 +97,37 @@ void notDuplicatedEmail_willSuccess() throws Exception { | |
verify(memberRegisterService, times(1)).checkEmailDuplicate(any(String.class)); | ||
} | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("getMember()는") | ||
class Context_getMember { | ||
|
||
@Test | ||
@DisplayName("회원 정보를 조회할 수 있다.") | ||
void _willSuccess() throws Exception { | ||
// given | ||
MemberInfoResponse memberInfoResponse = MemberInfoResponse.builder() | ||
.memberId(1L) | ||
.email("[email protected]") | ||
.name("test") | ||
.phoneNumber("010-1234-1234") | ||
.build(); | ||
|
||
given(memberGetService.getMember(any(Long.TYPE))) | ||
.willReturn(memberInfoResponse); | ||
|
||
// when then | ||
mockMvc.perform(get("/api/members/{memberId}", 1L)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.message").isString()) | ||
.andExpect(jsonPath("$.data").isMap()) | ||
.andExpect(jsonPath("$.data.memberId").isNumber()) | ||
.andExpect(jsonPath("$.data.email").isString()) | ||
.andExpect(jsonPath("$.data.name").isString()) | ||
.andExpect(jsonPath("$.data.phoneNumber").isString()) | ||
.andDo(print()); | ||
|
||
verify(memberGetService, times(1)).getMember(any(Long.class)); | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...test/java/com/backoffice/upjuyanolja/domain/member/unit/service/MemberGetServiceTest.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.backoffice.upjuyanolja.domain.member.unit.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import com.backoffice.upjuyanolja.domain.member.dto.response.MemberInfoResponse; | ||
import com.backoffice.upjuyanolja.domain.member.entity.Authority; | ||
import com.backoffice.upjuyanolja.domain.member.entity.Member; | ||
import com.backoffice.upjuyanolja.domain.member.exception.MemberNotFoundException; | ||
import com.backoffice.upjuyanolja.domain.member.repository.MemberRepository; | ||
import com.backoffice.upjuyanolja.domain.member.service.MemberGetService; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Transactional | ||
@ExtendWith(MockitoExtension.class) | ||
public class MemberGetServiceTest { | ||
|
||
@InjectMocks | ||
private MemberGetService memberGetService; | ||
|
||
@Mock | ||
private MemberRepository memberRepository; | ||
|
||
@Nested | ||
@DisplayName("getMember()는") | ||
class Context_getMember { | ||
|
||
@Test | ||
@DisplayName("회원 정보를 조회할 수 있다.") | ||
void _willSuccess() { | ||
// given | ||
Member member = Member.builder() | ||
.id(1L) | ||
.email("[email protected]") | ||
.password("$10$ygrAExVYmFTkZn2d0.Pk3Ot5CNZwIBjZH5f.WW0AnUq4w4PtBi9Nm") | ||
.name("test") | ||
.phone("010-1234-1234") | ||
.imageUrl( | ||
"https://fastly.picsum.photos/id/866/200/300.jpg?hmac=rcadCENKh4rD6MAp6V_ma-AyWv641M4iiOpe1RyFHeI") | ||
.authority(Authority.ROLE_USER) | ||
.build(); | ||
given(memberRepository.findById(any(Long.TYPE))).willReturn(Optional.of(member)); | ||
|
||
// when | ||
MemberInfoResponse result = memberGetService.getMember(1L); | ||
|
||
// then | ||
assertThat(result.memberId()).isEqualTo(1L); | ||
assertThat(result.email()).isEqualTo("[email protected]"); | ||
assertThat(result.name()).isEqualTo("test"); | ||
assertThat(result.phoneNumber()).isEqualTo("010-1234-1234"); | ||
|
||
verify(memberRepository, times(1)).findById(any(Long.TYPE)); | ||
} | ||
|
||
@Test | ||
@DisplayName("회원을 찾을 수 없으면, 익셉션을 던진다.") | ||
void memberNotFound_willFail() { | ||
// given | ||
given(memberRepository.findById(any(Long.TYPE))).willReturn(Optional.empty()); | ||
|
||
// when | ||
Throwable exception = assertThrows(MemberNotFoundException.class, () -> { | ||
memberGetService.getMember(1L); | ||
}); | ||
|
||
// then | ||
assertEquals(exception.getMessage(), "회원 정보를 찾을 수 없습니다."); | ||
|
||
verify(memberRepository, times(1)).findById(any(Long.TYPE)); | ||
} | ||
} | ||
} |