Repository navigation
fix: [ALT-308] 일반 공고 목록 검색어 및 조회 정합성 보완 #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ysw789
wants to merge
8
commits into
dev
Choose a base branch
from
fix/alt-308
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
424036f
fix: 일반 공고 목록과 건수에 기존 검색 조건 적용
ysw789 c495a4a
fix: [ALT-308] 공고 검색어 앞뒤 공백 제거 후 검색
ysw789 0276326
fix: [ALT-308] 공고 목록 마지막 페이지에서 커서를 내려주지 않도록 수정
ysw789 4e34975
fix: [ALT-308] 전각 공백만 입력한 검색어는 검색하지 않도록 수정
ysw789 e927c7e
test: [ALT-308] 공고 목록 커서 테스트 형식 정리 및 커서 createdAt 검증 추가
ysw789 72b2373
fix: [ALT-308] 지도 공고 목록 검색어 Swagger 설명을 일반 목록과 맞춤
ysw789 7b59808
test: [ALT-308] 공고 목록 커서 테스트를 기존 커서 페이지네이션 패턴 기준으로 변경
ysw789 240c0a5
fix: [ALT-308] 공고 목록 커서를 다음 페이지 유무와 관계없이 마지막 행 기준으로 반환하도록 되돌림
ysw789 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
128 changes: 128 additions & 0 deletions
128
...test/java/com/dreamteam/alter/application/posting/usecase/GetPostingsWithCursorTests.java
This file contains hidden or 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,128 @@ | ||
| package com.dreamteam.alter.application.posting.usecase; | ||
|
|
||
| import com.dreamteam.alter.adapter.inbound.common.dto.CursorDto; | ||
| import com.dreamteam.alter.adapter.inbound.common.dto.CursorPageRequest; | ||
| import com.dreamteam.alter.adapter.inbound.common.dto.CursorPageRequestDto; | ||
| import com.dreamteam.alter.adapter.inbound.general.posting.dto.PostingListFilterDto; | ||
| import com.dreamteam.alter.adapter.outbound.posting.persistence.readonly.PostingListResponse; | ||
| import com.dreamteam.alter.common.util.CursorUtil; | ||
| import com.dreamteam.alter.domain.posting.port.outbound.PostingQueryRepository; | ||
| import com.dreamteam.alter.domain.user.context.AppActor; | ||
| import com.dreamteam.alter.domain.user.entity.User; | ||
| import com.dreamteam.alter.domain.workspace.entity.BusinessType; | ||
| import com.dreamteam.alter.domain.workspace.entity.Workspace; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Spy; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.BDDMockito.given; | ||
| import static org.mockito.BDDMockito.then; | ||
| import static org.mockito.Mockito.lenient; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| @DisplayName("GetPostingsWithCursor - 일반 공고 목록 커서 조회") | ||
| class GetPostingsWithCursorTests { | ||
| @Mock PostingQueryRepository postingQueryRepository; | ||
| @Spy ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); | ||
| @InjectMocks GetPostingsWithCursor useCase; | ||
|
|
||
| private PostingListResponse row(Long id) { | ||
| PostingListResponse row = mock(PostingListResponse.class); | ||
| Workspace workspace = mock(Workspace.class); | ||
| lenient().when(workspace.getBusinessType()).thenReturn(BusinessType.create("카페", "설명")); | ||
| lenient().when(row.getWorkspace()).thenReturn(workspace); | ||
| lenient().when(row.getSchedules()).thenReturn(List.of()); | ||
| lenient().when(row.getId()).thenReturn(id); | ||
| lenient().when(row.getCreatedAt()).thenReturn(LocalDateTime.of(2026, 10, 3, 12, 0).minusDays(id)); | ||
| return row; | ||
| } | ||
|
|
||
| private AppActor actor() { | ||
| AppActor actor = mock(AppActor.class); | ||
| lenient().when(actor.getUser()).thenReturn(mock(User.class)); | ||
| return actor; | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("다음 페이지 유무와 관계없이 마지막으로 반환한 행을 가리키는 커서를 내려준다") | ||
| void cursorPointsAtLastReturnedRowRegardlessOfNextPage() { | ||
| // given | ||
| given(postingQueryRepository.getCountOfPostings(any())).willReturn(2L); | ||
| List<PostingListResponse> rows = List.of(row(1L), row(2L)); | ||
| given(postingQueryRepository.getPostingsWithCursor(any(), any(), any())) | ||
| .willReturn(rows); | ||
|
|
||
| // when | ||
| var result = useCase.execute(new CursorPageRequestDto(null, 10), new PostingListFilterDto(), actor()); | ||
|
|
||
| // then | ||
| assertThat(result.data()).extracting(dto -> dto.getId()).containsExactly(1L, 2L); | ||
| assertThat(result.page().pageSize()).isEqualTo(10); | ||
| assertThat(result.page().totalCount()).isEqualTo(2); | ||
| CursorDto cursor = CursorUtil.decodeCursor(result.page().cursor(), CursorDto.class, objectMapper); | ||
| assertThat(cursor.getId()).isEqualTo(2L); | ||
| assertThat(cursor.getCreatedAt()).isEqualTo(rows.get(1).getCreatedAt()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("요청한 페이지 크기 그대로 조회한다") | ||
| void repositoryIsAskedForRequestedPageSize() { | ||
| // given | ||
| given(postingQueryRepository.getCountOfPostings(any())).willReturn(1L); | ||
| List<PostingListResponse> rows = List.of(row(1L)); | ||
| given(postingQueryRepository.getPostingsWithCursor(any(), any(), any())) | ||
| .willReturn(rows); | ||
|
|
||
| // when | ||
| useCase.execute(new CursorPageRequestDto(null, 5), new PostingListFilterDto(), actor()); | ||
|
|
||
| // then | ||
| @SuppressWarnings("unchecked") | ||
| ArgumentCaptor<CursorPageRequest<CursorDto>> captor = ArgumentCaptor.forClass(CursorPageRequest.class); | ||
| then(postingQueryRepository).should().getPostingsWithCursor(captor.capture(), any(), any()); | ||
| assertThat(captor.getValue().pageSize()).isEqualTo(5); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("조건에 맞는 공고가 없으면 커서 없이 빈 목록을 반환한다") | ||
| void noMatchingPostingsReturnsEmptyWithoutCursor() { | ||
| // given | ||
| given(postingQueryRepository.getCountOfPostings(any())).willReturn(0L); | ||
|
|
||
| // when | ||
| var result = useCase.execute(new CursorPageRequestDto(null, 10), new PostingListFilterDto(), actor()); | ||
|
|
||
| // then | ||
| assertThat(result.page().cursor()).isNull(); | ||
| assertThat(result.page().totalCount()).isZero(); | ||
| assertThat(result.data()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("커서 이후 남은 공고가 없으면 커서 없이 빈 목록을 반환한다") | ||
| void noRowsAfterCursorReturnsEmptyWithoutCursor() { | ||
| // given | ||
| given(postingQueryRepository.getCountOfPostings(any())).willReturn(2L); | ||
| given(postingQueryRepository.getPostingsWithCursor(any(), any(), any())).willReturn(List.of()); | ||
|
|
||
| // when | ||
| var result = useCase.execute(new CursorPageRequestDto(null, 10), new PostingListFilterDto(), actor()); | ||
|
|
||
| // then | ||
| assertThat(result.page().cursor()).isNull(); | ||
| assertThat(result.page().totalCount()).isEqualTo(2); | ||
| assertThat(result.data()).isEmpty(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.