-
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.
- Loading branch information
Showing
9 changed files
with
282 additions
and
18 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(); | ||
} | ||
|
||
} |
Oops, something went wrong.