-
Notifications
You must be signed in to change notification settings - Fork 2
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
6 changed files
with
208 additions
and
210 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/test/java/toy/bookchat/bookchat/domain/chat/service/ChatServiceConcurrentTest.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
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,7 +2,7 @@ | |
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static toy.bookchat.bookchat.domain.common.Status.ACTIVE; | ||
import static toy.bookchat.bookchat.support.Status.ACTIVE; | ||
|
||
import java.util.Optional; | ||
import javax.persistence.EntityManager; | ||
|
@@ -17,144 +17,144 @@ | |
|
||
class UserEntityRepositoryTest extends RepositoryTest { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private EntityManager em; | ||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private EntityManager em; | ||
|
||
@Test | ||
void 사용자_이메일_OAuth2Provider를_구분으로_조회_성공() throws Exception { | ||
|
||
UserEntity userEntity1 = UserEntity.builder() | ||
.name("user") | ||
.email("[email protected]") | ||
.provider(OAuth2Provider.KAKAO) | ||
.build(); | ||
|
||
UserEntity userEntity2 = UserEntity.builder() | ||
.name("user") | ||
.email("[email protected]") | ||
.provider(OAuth2Provider.GOOGLE) | ||
.build(); | ||
|
||
userRepository.save(userEntity1); | ||
userRepository.save(userEntity2); | ||
|
||
Optional<UserEntity> kakaoUser = userRepository.findByEmailAndProvider( | ||
"[email protected]", OAuth2Provider.KAKAO); | ||
|
||
Optional<UserEntity> googleUser = userRepository.findByEmailAndProvider( | ||
"[email protected]", OAuth2Provider.GOOGLE); | ||
|
||
assertThat(kakaoUser).isNotEqualTo(googleUser); | ||
} | ||
|
||
@Test | ||
void 사용자_nickname_존재시_true_반환_성공() throws Exception { | ||
UserEntity userEntity = UserEntity.builder() | ||
.name("user") | ||
.email("[email protected]") | ||
.provider(OAuth2Provider.KAKAO) | ||
.nickname("nickname") | ||
.build(); | ||
|
||
userRepository.save(userEntity); | ||
|
||
boolean result = userRepository.existsByNickname("nickname"); | ||
|
||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
void 사용자_nickname_존재하지않을시_false_반환_성공() throws Exception { | ||
boolean result = userRepository.existsByNickname("nickname"); | ||
|
||
assertThat(result).isFalse(); | ||
} | ||
|
||
@Test | ||
void 사용자_이름으로_조회_성공() throws Exception { | ||
String userName = "KAKAO123456"; | ||
UserEntity userEntity = UserEntity.builder() | ||
.name(userName) | ||
.email("[email protected]") | ||
.provider(OAuth2Provider.KAKAO) | ||
.nickname("nickname") | ||
.build(); | ||
|
||
userRepository.save(userEntity); | ||
|
||
UserEntity findUserEntity = userRepository.findByName(userName).get(); | ||
|
||
assertThat(userEntity).isEqualTo(findUserEntity); | ||
} | ||
|
||
@Test | ||
void 사용자_삭제_성공() throws Exception { | ||
UserEntity userEntity = UserEntity.builder() | ||
.email("[email protected]") | ||
.name("testkakao") | ||
.nickname("nickname") | ||
.role(ROLE.USER) | ||
.profileImageUrl("[email protected]") | ||
.defaultProfileImageType(1) | ||
.build(); | ||
|
||
userRepository.save(userEntity); | ||
|
||
userRepository.delete(userEntity); | ||
|
||
Optional<UserEntity> ou = userRepository.findById(userEntity.getId()); | ||
assertThat(ou).isNotPresent(); | ||
} | ||
|
||
@Test | ||
void 변경_요청한_닉네임_이미_있을시_예외발생() throws Exception { | ||
UserEntity userEntity1 = UserEntity.builder() | ||
.nickname("user1") | ||
.build(); | ||
|
||
UserEntity userEntity2 = UserEntity.builder() | ||
.nickname("user2") | ||
.build(); | ||
|
||
userRepository.saveAndFlush(userEntity1); | ||
userRepository.save(userEntity2); | ||
userEntity2.changeUserNickname("user1"); | ||
|
||
assertThatThrownBy(() -> { | ||
userRepository.flush(); | ||
}).isInstanceOf(DataIntegrityViolationException.class); | ||
} | ||
|
||
@Test | ||
void 이미_존재하는_nickname인_경우_생성_실패() throws Exception { | ||
UserEntity userEntity1 = UserEntity.builder() | ||
.nickname("test nickname") | ||
.build(); | ||
|
||
userRepository.save(userEntity1); | ||
@Test | ||
void 사용자_이메일_OAuth2Provider를_구분으로_조회_성공() throws Exception { | ||
|
||
UserEntity userEntity1 = UserEntity.builder() | ||
.name("user") | ||
.email("[email protected]") | ||
.provider(OAuth2Provider.KAKAO) | ||
.build(); | ||
|
||
UserEntity userEntity2 = UserEntity.builder() | ||
.name("user") | ||
.email("[email protected]") | ||
.provider(OAuth2Provider.GOOGLE) | ||
.build(); | ||
|
||
userRepository.save(userEntity1); | ||
userRepository.save(userEntity2); | ||
|
||
Optional<UserEntity> kakaoUser = userRepository.findByEmailAndProvider( | ||
"[email protected]", OAuth2Provider.KAKAO); | ||
|
||
Optional<UserEntity> googleUser = userRepository.findByEmailAndProvider( | ||
"[email protected]", OAuth2Provider.GOOGLE); | ||
|
||
assertThat(kakaoUser).isNotEqualTo(googleUser); | ||
} | ||
|
||
@Test | ||
void 사용자_nickname_존재시_true_반환_성공() throws Exception { | ||
UserEntity userEntity = UserEntity.builder() | ||
.name("user") | ||
.email("[email protected]") | ||
.provider(OAuth2Provider.KAKAO) | ||
.nickname("nickname") | ||
.build(); | ||
|
||
userRepository.save(userEntity); | ||
|
||
boolean result = userRepository.existsByNickname("nickname"); | ||
|
||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
void 사용자_nickname_존재하지않을시_false_반환_성공() throws Exception { | ||
boolean result = userRepository.existsByNickname("nickname"); | ||
|
||
assertThat(result).isFalse(); | ||
} | ||
|
||
@Test | ||
void 사용자_이름으로_조회_성공() throws Exception { | ||
String userName = "KAKAO123456"; | ||
UserEntity userEntity = UserEntity.builder() | ||
.name(userName) | ||
.email("[email protected]") | ||
.provider(OAuth2Provider.KAKAO) | ||
.nickname("nickname") | ||
.build(); | ||
|
||
userRepository.save(userEntity); | ||
|
||
UserEntity findUserEntity = userRepository.findByName(userName).get(); | ||
|
||
assertThat(userEntity).isEqualTo(findUserEntity); | ||
} | ||
|
||
@Test | ||
void 사용자_삭제_성공() throws Exception { | ||
UserEntity userEntity = UserEntity.builder() | ||
.email("[email protected]") | ||
.name("testkakao") | ||
.nickname("nickname") | ||
.role(ROLE.USER) | ||
.profileImageUrl("[email protected]") | ||
.defaultProfileImageType(1) | ||
.build(); | ||
|
||
userRepository.save(userEntity); | ||
|
||
userRepository.delete(userEntity); | ||
|
||
Optional<UserEntity> ou = userRepository.findById(userEntity.getId()); | ||
assertThat(ou).isNotPresent(); | ||
} | ||
|
||
@Test | ||
void 변경_요청한_닉네임_이미_있을시_예외발생() throws Exception { | ||
UserEntity userEntity1 = UserEntity.builder() | ||
.nickname("user1") | ||
.build(); | ||
|
||
UserEntity userEntity2 = UserEntity.builder() | ||
.nickname("user2") | ||
.build(); | ||
|
||
userRepository.saveAndFlush(userEntity1); | ||
userRepository.save(userEntity2); | ||
userEntity2.changeUserNickname("user1"); | ||
|
||
assertThatThrownBy(() -> { | ||
userRepository.flush(); | ||
}).isInstanceOf(DataIntegrityViolationException.class); | ||
} | ||
|
||
@Test | ||
void 이미_존재하는_nickname인_경우_생성_실패() throws Exception { | ||
UserEntity userEntity1 = UserEntity.builder() | ||
.nickname("test nickname") | ||
.build(); | ||
|
||
userRepository.save(userEntity1); | ||
|
||
UserEntity userEntity2 = UserEntity.builder() | ||
.nickname("test nickname") | ||
.build(); | ||
assertThatThrownBy(() -> userRepository.save(userEntity2)) | ||
.isInstanceOf(DataIntegrityViolationException.class); | ||
} | ||
|
||
@Test | ||
void 사용자_계정생성시_기본_상태값_active로_생성_성공() throws Exception { | ||
UserEntity userEntity = UserEntity.builder() | ||
.nickname("user1") | ||
.build(); | ||
|
||
userRepository.save(userEntity); | ||
|
||
em.flush(); | ||
em.clear(); | ||
|
||
UserEntity findUserEntity = userRepository.findById(userEntity.getId()).get(); | ||
UserEntity userEntity2 = UserEntity.builder() | ||
.nickname("test nickname") | ||
.build(); | ||
assertThatThrownBy(() -> userRepository.save(userEntity2)) | ||
.isInstanceOf(DataIntegrityViolationException.class); | ||
} | ||
|
||
@Test | ||
void 사용자_계정생성시_기본_상태값_active로_생성_성공() throws Exception { | ||
UserEntity userEntity = UserEntity.builder() | ||
.nickname("user1") | ||
.build(); | ||
|
||
userRepository.save(userEntity); | ||
|
||
em.flush(); | ||
em.clear(); | ||
|
||
UserEntity findUserEntity = userRepository.findById(userEntity.getId()).get(); | ||
|
||
assertThat(findUserEntity.getStatus()).isEqualTo(ACTIVE); | ||
} | ||
assertThat(findUserEntity.getStatus()).isEqualTo(ACTIVE); | ||
} | ||
} |
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
3 changes: 1 addition & 2 deletions
3
src/test/java/toy/bookchat/bookchat/support/RateLimiterAopTest.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
Oops, something went wrong.