-
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.
* #119 test: userRepository 테스트 코드 작성 - findByUserToken() - existsByEmail() - findByEmail() - findAllByUserToken() - findAllByUserId() * #119 test: userService 테스트 코드 작성 - updateMyInfo() - nullExceptionUpdateMyInfo() - search() * #119 fix: 유저 find 기능 수정 - findAllByUserToken() - findAllByUserId()
- Loading branch information
Showing
10 changed files
with
268 additions
and
35 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
src/main/java/com/seoultech/synergybe/domain/email/MailService.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
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
7 changes: 4 additions & 3 deletions
7
src/main/java/com/seoultech/synergybe/domain/user/repository/UserRepositoryCustom.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,10 +1,11 @@ | ||
package com.seoultech.synergybe.domain.user.repository; | ||
|
||
import com.seoultech.synergybe.domain.user.User; | ||
import com.seoultech.synergybe.domain.user.dto.response.GetUserAccountResponse; | ||
|
||
public interface UserRepositoryCustom { | ||
GetUserAccountResponse findUserAccountByEmail(String email); | ||
import java.util.List; | ||
|
||
public interface UserRepositoryCustom { | ||
User findByEmail(String email); | ||
List<User> findAllByUserToken(List<String> userToken); | ||
List<User> findAllByUserId(List<Long> userIds); | ||
} |
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
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); | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.