-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: 필터링 API 파싱 오류 수정 #604 #605
Changes from all commits
1c35abe
c5173f8
84488b0
7c5d4c8
c3e99e6
173a58c
0e9491d
283d21f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Backend CI/CD multi prod | ||
name: Backend CI/CD multi dev | ||
|
||
on: | ||
push: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ public record LoginRequest( | |
String nickname | ||
) { | ||
public LoginRequest { | ||
if (!Objects.isNull(nickname)) { | ||
if (Objects.nonNull(nickname)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 커밋달고 나서 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사람 생각하는거 다 똑같구만요~ ㅋㅋㅋㅋㅋㅋㅋㅋ |
||
nickname = nickname.trim(); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ public static List<MemoryFilter> findAllByName(List<String> filters) { | |
.map(name -> MemoryFilter.findByName(name.trim())) | ||
.filter(Optional::isPresent) | ||
.map(Optional::get) | ||
.distinct() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 똑같은 필터가 두 개 들어올 수도 있기 때문에, 불필요한 연산 방지를 위해서 중복 제거 작업이 꼭 필요하겠네요! 👍 |
||
.toList(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.junit.jupiter.params.provider.NullSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
@@ -26,13 +27,21 @@ public class MemorySortTest extends ServiceSliceTest { | |
private MemoryRepository memoryRepository; | ||
|
||
@DisplayName("정렬명이 주어졌을 때 대소문자 구분 없이 MemorySort을 반환한다.") | ||
@Test | ||
void findByNameWithValidSort() { | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"UPDATED, UPDATED", | ||
"NEWEST, NEWEST", | ||
"OLDEST, OLDEST", | ||
"updated, UPDATED", | ||
"newest, NEWEST", | ||
"oldest, OLDEST" | ||
}) | ||
void findByNameWithValidSort(String name, MemorySort sort) { | ||
// when | ||
MemorySort result = MemorySort.findByName("newest"); | ||
MemorySort result = MemorySort.findByName(name); | ||
|
||
// then | ||
assertThat(result).isEqualTo(MemorySort.NEWEST); | ||
assertThat(result).isEqualTo(sort); | ||
} | ||
Comment on lines
29
to
45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@DisplayName("정렬명이 주어졌을 때 대소문자 구분 없이 MemorySort을 반환한다.")
@ParameterizedTest
@EnumSource(MemorySort.class)
void findByNameWithValidSort(MemorySort sort) {
// when
MemorySort resultUpper = MemorySort.findByName(sort.name());
MemorySort resultLower = MemorySort.findByName(sort.name().toLowerCase());
// then
assertAll(
() -> assertThat(resultUpper).isEqualTo(sort),
() -> assertThat(resultLower).isEqualTo(sort)
);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추가로, Enum으로 테스트를 진행했을 때 검증 결과 값으로 검증을 하는 것이 어색하게 다가온 것도 있었어요 ㅎㅎ |
||
|
||
@DisplayName("유효하지 않거나 null인 정렬명이 주어졌을 때 기본값인 UPDATED를 반환한다.") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DTO 클래스의 테스트를 만들어서, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.staccato.memory.service.dto.request; | ||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import com.staccato.memory.service.MemoryFilter; | ||
import com.staccato.memory.service.MemorySort; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class MemoryReadRequestTest { | ||
@DisplayName("필터가 주어졌을 때 올바른 필터 목록을 반환한다") | ||
@Test | ||
void getFiltersWithValidFilters() { | ||
// given | ||
MemoryReadRequest request = new MemoryReadRequest("TERM, term", "NEWEST"); | ||
|
||
// when | ||
List<MemoryFilter> filters = request.getFilters(); | ||
|
||
// then | ||
assertThat(filters).hasSize(1).containsOnly(MemoryFilter.TERM); | ||
} | ||
|
||
@DisplayName("필터가 주어지지 않았을 때 빈 필터 목록을 반환한다") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. '필터 목록'이라고 하지 않으면, 정렬도 생각할 수 있기 때문에 확실히 좋은 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! 한글이 좋아서 한그롤...바꿧습니다 ㅋㅋ |
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
void getFiltersWithNullOrEmptyFilters(String filters) { | ||
// given | ||
MemoryReadRequest request = new MemoryReadRequest(filters, "NEWEST"); | ||
|
||
// when | ||
List<MemoryFilter> result = request.getFilters(); | ||
|
||
// then | ||
assertThat(result).isEmpty(); | ||
} | ||
|
||
@DisplayName("정렬이 주어지지 않았을 때 기본 정렬 기준을 반환한다") | ||
@ParameterizedTest | ||
@NullAndEmptySource | ||
void getSortWithNullOrEmptyFilters(String sort) { | ||
// given | ||
MemoryReadRequest request = new MemoryReadRequest(null, sort); | ||
|
||
// when | ||
MemorySort result = request.getSort(); | ||
|
||
// then | ||
assertThat(result).isEqualTo(MemorySort.UPDATED); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용자가 필요할 때 수동으로 실행할 수 있도록 설정하는 기능이네요! 👍