-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into refactor/339
- Loading branch information
Showing
9 changed files
with
281 additions
and
14 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
10 changes: 8 additions & 2 deletions
10
...eg/drinkeg/domain/member/dto/JoinDTO.java → ...rinkeg/domain/member/dto/JoinRequest.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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package com.drinkeg.drinkeg.domain.member.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Setter | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Getter | ||
public class JoinDTO { | ||
@Builder | ||
public class JoinRequest { | ||
|
||
private String username; | ||
private String password; | ||
private String rePassword; | ||
|
||
|
||
} |
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
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 |
---|---|---|
|
@@ -48,4 +48,4 @@ public String createJwt(String category,String username, String role, Long expir | |
|
||
|
||
|
||
} | ||
} |
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
101 changes: 101 additions & 0 deletions
101
src/test/java/com/drinkeg/drinkeg/domain/member/service/JoinServiceTest.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,101 @@ | ||
package com.drinkeg.drinkeg.domain.member.service; | ||
|
||
import com.drinkeg.drinkeg.IntegrationTestSupport; | ||
import com.drinkeg.drinkeg.domain.member.domain.Member; | ||
import com.drinkeg.drinkeg.domain.member.dto.JoinRequest; | ||
import com.drinkeg.drinkeg.domain.member.enums.Role; | ||
import com.drinkeg.drinkeg.domain.member.repostitory.MemberRepository; | ||
import com.drinkeg.drinkeg.global.apipayLoad.code.status.ErrorStatus; | ||
import com.drinkeg.drinkeg.global.exception.GeneralException; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Optional; | ||
|
||
public class JoinServiceTest extends IntegrationTestSupport { | ||
|
||
@Autowired | ||
MemberRepository memberRepository; | ||
|
||
@Autowired | ||
JoinService joinService; | ||
|
||
@DisplayName("새로운 멤버 정보를 저장한다.") | ||
@Test | ||
void joinMember(){ | ||
|
||
//given | ||
JoinRequest joinRequest = createJoinRequest("itsme", "22azaz1234", "22azaz1234"); | ||
|
||
//when | ||
joinService.join(joinRequest); | ||
|
||
//then | ||
Optional<Member> savedMember = memberRepository.findByUsername("itsme"); | ||
Member member = savedMember.get(); | ||
assertThat(member.getUsername()).isEqualTo("itsme"); | ||
assertThat(member.getPassword()).isNotEqualTo("22azaz1234"); //bCryptPasswordEncoder는 매번 다른 값을 생성 | ||
assertThat(member.isAdult()).isFalse(); | ||
|
||
|
||
} | ||
|
||
@Test | ||
@DisplayName("중복된 사용자 이름으로 회원가입 시 예외를 반환한다.") | ||
void joinMember_DuplicateUsername() { | ||
// Given | ||
memberRepository.save(createMember("itsme", "notPassword")); | ||
JoinRequest joinRequest = createJoinRequest("itsme", "22azaz1234", "22azaz1234"); | ||
|
||
// When & Then | ||
assertThatThrownBy(() -> joinService.join(joinRequest)) | ||
.isInstanceOf(GeneralException.class) | ||
.hasMessageContaining(ErrorStatus.MEMBER_ALREADY_EXIST.getMessage()); | ||
} | ||
|
||
@Test | ||
@DisplayName("비밀번호와 비밀번호 확인이 일치하지 않을 경우 예외를 반환한다.") | ||
void joinMember_PasswordMismatch() { | ||
// Given | ||
JoinRequest joinRequest = createJoinRequest("itsme", "22azaz1234", "differentPassword"); | ||
|
||
// When & Then | ||
assertThatThrownBy(() -> joinService.join(joinRequest)) | ||
.isInstanceOf(GeneralException.class) | ||
.hasMessageContaining(ErrorStatus.PASSWORD_NOT_MATCH.getMessage()); | ||
} | ||
|
||
@Test | ||
@DisplayName("비밀번호가 유효하지 않을 경우 예외를 반환한다.") | ||
void joinMember_InvalidPassword() { | ||
// Given | ||
JoinRequest joinRequest = createJoinRequest("itsme", "short", "short"); // 예: 너무 짧은 비밀번호 | ||
|
||
// When & Then | ||
assertThatThrownBy(() -> joinService.join(joinRequest)) | ||
.isInstanceOf(GeneralException.class) | ||
.hasMessageContaining(ErrorStatus.PASSWORD_NOT_INVALID.getMessage()); | ||
} | ||
private JoinRequest createJoinRequest(String username, String password, String rePassword){ | ||
return JoinRequest.builder() | ||
.username(username) | ||
.password(password) | ||
.rePassword(rePassword) | ||
.build(); | ||
|
||
|
||
} | ||
|
||
private Member createMember(String username,String password) { | ||
return Member.builder() | ||
.username(username) | ||
.password(password) | ||
.isFirst(false) | ||
.build(); | ||
} | ||
|
||
} |
157 changes: 156 additions & 1 deletion
157
src/test/java/com/drinkeg/drinkeg/domain/member/service/MemberServiceTest.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 |
---|---|---|
@@ -1,4 +1,159 @@ | ||
package com.drinkeg.drinkeg.domain.member.service; | ||
|
||
public class MemberServiceTest { | ||
import com.drinkeg.drinkeg.IntegrationTestSupport; | ||
import com.drinkeg.drinkeg.domain.member.domain.Member; | ||
import com.drinkeg.drinkeg.domain.member.dto.MemberInfoResponse; | ||
import com.drinkeg.drinkeg.domain.member.enums.Provider; | ||
import com.drinkeg.drinkeg.domain.member.enums.Role; | ||
import com.drinkeg.drinkeg.domain.member.repostitory.MemberRepository; | ||
import com.drinkeg.drinkeg.global.apipayLoad.code.status.ErrorStatus; | ||
import com.drinkeg.drinkeg.global.exception.GeneralException; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
|
||
public class MemberServiceTest extends IntegrationTestSupport { | ||
|
||
@Autowired | ||
MemberRepository memberRepository; | ||
|
||
@Autowired | ||
MemberService memberService; | ||
|
||
@DisplayName("존재하는 username으로 사용자 정보를 불러온다.") | ||
@Test | ||
void findByUsernameTest(){ | ||
|
||
//given | ||
Member member1 = memberRepository.save(createMember("user1", "윤다영","[email protected]","서울","Drinkeg", true,"https://drinkeg-bucket-1.s3.ap-northeast-2.amazonaws.com/member/profile/70af4bd2-717c-48d8-93d5-1a563de091a2" )); | ||
Member member2 = memberRepository.save(createMember("user2","주민영","[email protected]","광주","Kakao", true ,null)); | ||
|
||
|
||
//when | ||
MemberInfoResponse memberInfoResponse = memberService.showMemberInfo("user1"); | ||
|
||
//then | ||
assertThat(memberInfoResponse).isNotNull(); | ||
assertThat(memberInfoResponse) | ||
.extracting( | ||
MemberInfoResponse::getUsername, // memberInfoResponse.getUsername() 호출 | ||
MemberInfoResponse::getEmail, // memberInfoResponse.getEmail() 호출 | ||
MemberInfoResponse::getCity, // memberInfoResponse.getCity() 호출 | ||
MemberInfoResponse::getAuthType, // memberInfoResponse.getAuthType() 호출 | ||
MemberInfoResponse::isAdult, | ||
MemberInfoResponse::getImageUrl | ||
) | ||
.containsExactly( | ||
"윤다영", | ||
"[email protected]", | ||
"서울", | ||
"Drinkeg", | ||
true, | ||
"https://drinkeg-bucket-1.s3.ap-northeast-2.amazonaws.com/member/profile/70af4bd2-717c-48d8-93d5-1a563de091a2" | ||
); | ||
} | ||
|
||
@DisplayName("존재하지 않는 username으로 조회 시 GeneralException을 반환한다") | ||
@Test | ||
void showMemberInfo_ThrowsException() { | ||
// given | ||
|
||
memberRepository.save(createMember("user1", "윤다영", "[email protected]", "서울", "Drinkeg", true," https://drinkeg-bucket-1.s3.ap-northeast-2.amazonaws.com/member/profile/70af4bd2-717c-48d8-93d5-1a563de091a2")); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> memberService.showMemberInfo("user2")) | ||
.isInstanceOf(GeneralException.class) | ||
.hasMessageContaining(ErrorStatus.MEMBER_NOT_FOUND.getMessage()); | ||
} | ||
|
||
@DisplayName("member의 해당 속성 값이 null일 경우 null을 그대로 반환한다.") | ||
@Test | ||
void memberInfoResponse_is_null_Test(){ | ||
|
||
//given | ||
Member member2 = memberRepository.save(createMember("user1","주민영","[email protected]","광주","Kakao", true ,null)); | ||
|
||
//when | ||
MemberInfoResponse memberInfoResponse = memberService.showMemberInfo("user1"); | ||
|
||
//then | ||
assertThat(memberInfoResponse).isNotNull(); | ||
assertThat(memberInfoResponse) | ||
.extracting( | ||
MemberInfoResponse::getUsername, // memberInfoResponse.getUsername() 호출 | ||
MemberInfoResponse::getEmail, // memberInfoResponse.getEmail() 호출 | ||
MemberInfoResponse::getCity, // memberInfoResponse.getCity() 호출 | ||
MemberInfoResponse::getAuthType, // memberInfoResponse.getAuthType() 호출 | ||
MemberInfoResponse::isAdult, | ||
MemberInfoResponse::getImageUrl | ||
) | ||
.containsExactly( | ||
"주민영", | ||
"[email protected]", | ||
"광주", | ||
"Kakao", | ||
true, | ||
null ); | ||
} | ||
|
||
@Test | ||
@DisplayName("존재하는 memberId로 멤버를 조회한다.") | ||
void getMemberById_Success() { | ||
// Given | ||
Member member1 = memberRepository.save(createMember("user1", "윤다영", "[email protected]", "서울", "Drinkeg", true," https://drinkeg-bucket-1.s3.ap-northeast-2.amazonaws.com/member/profile/70af4bd2-717c-48d8-93d5-1a563de091a2")); | ||
|
||
// When | ||
Member foundMember = memberService.getMemberById(member1.getId()); | ||
|
||
// Then | ||
assertThat(foundMember).isNotNull(); | ||
assertThat(foundMember.getUsername()).isEqualTo("user1"); | ||
assertThat(foundMember.getName()).isEqualTo("윤다영"); | ||
assertThat(foundMember.getEmail()).isEqualTo("[email protected]"); | ||
assertThat(foundMember.getRegion()).isEqualTo("서울"); | ||
assertThat(foundMember.getProvider().getValue()).isEqualTo("Drinkeg"); | ||
assertThat(foundMember.isAdult()).isTrue(); | ||
assertThat(foundMember.getImageUrl()).isNull(); | ||
} | ||
|
||
@Test | ||
@DisplayName("존재하지 않는 memberId로 조회 시 GeneralException 발생") | ||
void getMemberById_Failure_MemberNotFound() { | ||
// Given | ||
Long nonExistentId = 999L; | ||
|
||
// When & Then | ||
assertThatThrownBy(() -> memberService.getMemberById(nonExistentId)) | ||
.isInstanceOf(GeneralException.class) | ||
.hasMessageContaining(ErrorStatus.MEMBER_NOT_FOUND.getMessage()); | ||
} | ||
|
||
|
||
|
||
private Member createMember( | ||
String username, | ||
String name, | ||
String email, | ||
String city, | ||
String authType, | ||
boolean adult, | ||
String imageUrl | ||
) { | ||
return Member.builder() | ||
.username(username) | ||
.name(name) | ||
.email(email) | ||
.region(city) | ||
.provider(Provider.fromValue(authType)) | ||
.isAdult(adult) | ||
.role(Role.ROLE_USER) | ||
.isFirst(false) | ||
.imageUrl(imageUrl) | ||
.build(); | ||
} | ||
} |