Skip to content

Commit 3e33f2a

Browse files
committed
Merge branch 'feature/user-search' into develop
2 parents b591bbb + ba31381 commit 3e33f2a

File tree

2 files changed

+2
-69
lines changed

2 files changed

+2
-69
lines changed

src/main/java/com/example/log4u/domain/user/repository/UserRepository.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ public interface UserRepository extends JpaRepository<User, Long> {
2121

2222
@Query(value = """
2323
SELECT u FROM User u
24-
LEFT JOIN (SELECT f.targetId, COUNT(f) as followerCount
25-
FROM Follow f
26-
GROUP BY f.targetId) fc
27-
ON u.userId = fc.targetId
2824
WHERE (:nickname IS NULL OR LOWER(u.nickname) LIKE LOWER(CONCAT('%', :nickname, '%')))
2925
AND u.userId < :cursorId
30-
ORDER BY fc.followerCount DESC NULLS LAST, u.userId DESC
26+
ORDER BY u.userId DESC
3127
""")
3228
Slice<User> searchUsersByCursor(
3329
@Param("nickname") String nickname,

src/test/java/com/example/log4u/domain/user/service/UserServiceTest.java

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -126,70 +126,7 @@ void shouldThrowExceptionWhenUserNotFound() {
126126
assertThrows(UserNotFoundException.class, () -> userService.getUserById(userId));
127127
verify(userRepository).findById(userId);
128128
}
129-
130-
@Test
131-
@DisplayName("닉네임으로 유저를 검색하고 팔로워 수 높은 순으로 정렬해야 한다")
132-
void shouldSearchUsersByNicknameAndSortByFollowerCount() {
133-
// given
134-
String nickname = "test";
135-
Long cursorId = null;
136-
int size = 10;
137-
138-
// 테스트용 유저 목록 생성
139-
User user1 = UserFixture.createUserWithId(1L, "User1", "test1");
140-
User user2 = UserFixture.createUserWithId(2L, "User2", "test2");
141-
User user3 = UserFixture.createUserWithId(3L, "User3", "test3");
142-
143-
List<User> users = List.of(user1, user2, user3);
144-
Slice<User> userSlice = new SliceImpl<>(users, PageRequest.of(0, size), false);
145-
146-
// Mock 설정
147-
when(userRepository.searchUsersByCursor(
148-
eq(nickname),
149-
eq(Long.MAX_VALUE),
150-
ArgumentMatchers.any(PageRequest.class)))
151-
.thenReturn(userSlice);
152-
153-
// 각 유저의 팔로워/팔로잉 수 설정
154-
when(followRepository.countByTargetId(1L)).thenReturn(10L);
155-
when(followRepository.countByInitiatorId(1L)).thenReturn(5L);
156-
157-
when(followRepository.countByTargetId(2L)).thenReturn(20L);
158-
when(followRepository.countByInitiatorId(2L)).thenReturn(15L);
159-
160-
when(followRepository.countByTargetId(3L)).thenReturn(30L);
161-
when(followRepository.countByInitiatorId(3L)).thenReturn(25L);
162-
163-
// when
164-
PageResponse<UserProfileResponseDto> result = userService.searchUsersByCursor(nickname, cursorId, size);
165-
166-
// then
167-
assertNotNull(result);
168-
assertEquals(3, result.list().size());
169-
170-
// 팔로워 수 확인
171-
assertEquals(10L, result.list().get(0).followers());
172-
assertEquals(20L, result.list().get(1).followers());
173-
assertEquals(30L, result.list().get(2).followers());
174-
175-
// 팔로잉 수 확인
176-
assertEquals(5L, result.list().get(0).followings());
177-
assertEquals(15L, result.list().get(1).followings());
178-
assertEquals(25L, result.list().get(2).followings());
179-
180-
// 다음 커서 확인
181-
assertEquals(3L, result.pageInfo().nextCursor());
182-
183-
// 메서드 호출 확인
184-
verify(userRepository).searchUsersByCursor(
185-
eq(nickname),
186-
eq(Long.MAX_VALUE),
187-
ArgumentMatchers.any(PageRequest.class));
188-
189-
verify(followRepository, times(3)).countByTargetId(anyLong());
190-
verify(followRepository, times(3)).countByInitiatorId(anyLong());
191-
}
192-
129+
193130
@Test
194131
@DisplayName("검색 결과가 없으면 빈 리스트를 반환해야 한다")
195132
void shouldReturnEmptyListWhenNoSearchResults() {

0 commit comments

Comments
 (0)