-
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.
- findByUserToken() - existsByEmail() - findByEmail() - findAllByUserToken() - findAllByUserId()
- Loading branch information
Showing
1 changed file
with
158 additions
and
0 deletions.
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
src/test/java/com/seoultech/synergybe/domain/user/UserRepositoryTest.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,158 @@ | ||
package com.seoultech.synergybe.domain.user; | ||
|
||
import com.seoultech.synergybe.domain.common.CustomPasswordEncoder; | ||
import com.seoultech.synergybe.domain.user.repository.UserRepository; | ||
import com.seoultech.synergybe.domain.user.vo.UserEmail; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
public class UserRepositoryTest { | ||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Autowired | ||
private CustomPasswordEncoder passwordEncoder; | ||
|
||
@Test | ||
void findByUserToken() { | ||
// given | ||
String userToken = "usr_token"; | ||
User user = User.builder() | ||
.id(1L) | ||
.userToken(userToken) | ||
.email("[email protected]") | ||
.password("password") | ||
.major("major") | ||
.name("name") | ||
.passwordEncoder(passwordEncoder) | ||
.build(); | ||
userRepository.save(user); | ||
|
||
// when | ||
User savedUser = userRepository.findByUserToken(userToken).orElseThrow(); | ||
|
||
// then | ||
assertThat(savedUser.getUserToken()).isEqualTo(userToken); | ||
} | ||
|
||
@Test | ||
void existsByEmail() { | ||
// given | ||
String userEmail = "[email protected]"; | ||
User user = User.builder() | ||
.id(1L) | ||
.userToken("userToken") | ||
.email(userEmail) | ||
.password("password") | ||
.major("major") | ||
.name("name") | ||
.passwordEncoder(passwordEncoder) | ||
.build(); | ||
userRepository.save(user); | ||
UserEmail userEmailEmbed = new UserEmail(userEmail); | ||
|
||
// when | ||
boolean isExist = userRepository.existsByEmail(userEmailEmbed); | ||
|
||
// then | ||
assertThat(isExist).isTrue(); | ||
} | ||
|
||
@Test | ||
void findByEmail() { | ||
String userEmail = "[email protected]"; | ||
User user = User.builder() | ||
.id(1L) | ||
.userToken("userToken") | ||
.email(userEmail) | ||
.password("password") | ||
.major("major") | ||
.name("name") | ||
.passwordEncoder(passwordEncoder) | ||
.build(); | ||
userRepository.save(user); | ||
|
||
// when | ||
User savedUser = userRepository.findByEmail(userEmail); | ||
|
||
// then | ||
assertThat(savedUser).isNotNull(); | ||
} | ||
|
||
@Test | ||
void findAllByUserToken() { | ||
String userToken = "usr_token"; | ||
String userToken2 = "usr_token2"; | ||
User user = User.builder() | ||
.id(1L) | ||
.userToken(userToken) | ||
.email("[email protected]") | ||
.password("password") | ||
.major("major") | ||
.name("name") | ||
.passwordEncoder(passwordEncoder) | ||
.build(); | ||
|
||
User user2 = User.builder() | ||
.id(2L) | ||
.userToken(userToken2) | ||
.email("[email protected]") | ||
.password("password") | ||
.major("major") | ||
.name("name") | ||
.passwordEncoder(passwordEncoder) | ||
.build(); | ||
userRepository.save(user); | ||
userRepository.save(user2); | ||
|
||
// when | ||
List<User> users = userRepository.findAllByUserToken(List.of(userToken, userToken2)); | ||
|
||
// then | ||
assertThat(users.size()).isEqualTo(2); | ||
} | ||
|
||
@Test | ||
void findAllByUserId() { | ||
Long userId = 1L; | ||
Long userId2 = 2L; | ||
User user = User.builder() | ||
.id(userId) | ||
.userToken("userToken") | ||
.email("[email protected]") | ||
.password("password") | ||
.major("major") | ||
.name("name") | ||
.passwordEncoder(passwordEncoder) | ||
.build(); | ||
|
||
User user2 = User.builder() | ||
.id(userId2) | ||
.userToken("userToken2") | ||
.email("[email protected]") | ||
.password("password") | ||
.major("major") | ||
.name("name") | ||
.passwordEncoder(passwordEncoder) | ||
.build(); | ||
userRepository.save(user); | ||
userRepository.save(user2); | ||
|
||
// when | ||
List<User> users = userRepository.findAllByUserId(List.of(userId, userId2)); | ||
|
||
// then | ||
assertThat(users.size()).isEqualTo(2); | ||
} | ||
|
||
|
||
|
||
} |