Skip to content

Commit

Permalink
chore: 검색 엔진의 질의문 해석 방식 테스트 추가 #138
Browse files Browse the repository at this point in the history
meilisearch는 쿼리가 문장으로 되어 있어도, 쿼리의 단어를 나눠서 각각에 대해 검색하는 기능은 없다는 것을 확인하는 테스트 추가
  • Loading branch information
seungyeop-lee committed Jul 13, 2024
1 parent 58d6ac6 commit 39e7e56
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import vook.server.api.domain.user.model.User;
import vook.server.api.domain.vocabulary.logic.TermLogic;
import vook.server.api.domain.vocabulary.logic.VocabularyLogic;
import vook.server.api.domain.vocabulary.logic.dto.TermCreateAllCommand;
import vook.server.api.domain.vocabulary.logic.dto.TermCreateCommand;
import vook.server.api.domain.vocabulary.logic.dto.VocabularyCreateCommand;
import vook.server.api.domain.vocabulary.model.Term;
Expand Down Expand Up @@ -52,4 +53,24 @@ public Term createTerm(Vocabulary vocabulary, String suffix) {
.synonyms(List.of("testSynonymA" + suffix, "testSynonymB" + suffix))
.build());
}

public void createTerms(Vocabulary vocabulary, List<TermInfo> termInfos) {
termLogic.createAll(TermCreateAllCommand.builder()
.vocabularyUid(vocabulary.getUid())
.termInfos(termInfos.stream()
.map(termInfo -> new TermCreateAllCommand.TermInfo(
termInfo.term(),
termInfo.meaning(),
termInfo.synonyms()
))
.toList())
.build());
}

public record TermInfo(
String term,
String meaning,
List<String> synonyms
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static vook.server.api.testhelper.creator.TestVocabularyCreator.TermInfo;

@Transactional
class SearchTermUseCaseTest extends IntegrationTestBase {
Expand All @@ -25,19 +26,19 @@ class SearchTermUseCaseTest extends IntegrationTestBase {
@Autowired
TestUserCreator testUserCreator;
@Autowired
TestVocabularyCreator testVocabularyCreator;
TestVocabularyCreator vocaCreator;

@Test
@DisplayName("용어 검색 - 정상")
void searchTerms() {
// given
User user = testUserCreator.createCompletedOnboardingUser();
Vocabulary vocabulary1 = testVocabularyCreator.createVocabulary(user);
testVocabularyCreator.createTerm(vocabulary1, "하이브리드앱");
testVocabularyCreator.createTerm(vocabulary1, "네이티브앱");
Vocabulary vocabulary2 = testVocabularyCreator.createVocabulary(user);
testVocabularyCreator.createTerm(vocabulary2, "하이브리드웹");
testVocabularyCreator.createTerm(vocabulary2, "네이티브웹");
Vocabulary vocabulary1 = vocaCreator.createVocabulary(user);
vocaCreator.createTerm(vocabulary1, "하이브리드앱");
vocaCreator.createTerm(vocabulary1, "네이티브앱");
Vocabulary vocabulary2 = vocaCreator.createVocabulary(user);
vocaCreator.createTerm(vocabulary2, "하이브리드웹");
vocaCreator.createTerm(vocabulary2, "네이티브웹");

SearchTermUseCase.Command command = SearchTermUseCase.Command.builder()
.userUid(user.getUid())
Expand Down Expand Up @@ -75,11 +76,11 @@ void searchTerms() {
void searchTerms_userDoesNotOwnVocabulary() {
// given
User user = testUserCreator.createCompletedOnboardingUser();
testVocabularyCreator.createVocabulary(user);
testVocabularyCreator.createVocabulary(user);
vocaCreator.createVocabulary(user);
vocaCreator.createVocabulary(user);

User anotherUser = testUserCreator.createCompletedOnboardingUser();
Vocabulary anotherVocabulary = testVocabularyCreator.createVocabulary(anotherUser);
Vocabulary anotherVocabulary = vocaCreator.createVocabulary(anotherUser);

SearchTermUseCase.Command command = SearchTermUseCase.Command.builder()
.userUid(user.getUid())
Expand All @@ -91,4 +92,40 @@ void searchTerms_userDoesNotOwnVocabulary() {
assertThatThrownBy(() -> searchTermUseCase.execute(command))
.isInstanceOf(VocabularyPolicy.NotValidVocabularyOwnerException.class);
}

@Test
@DisplayName("용어 검색 - 검색 쿼리내 단어가 몇 개이던, 첫번째 단어 기준으로 검색이 된다.")
void searchTerms_queryIsTooLong() {
// given
User user = testUserCreator.createCompletedOnboardingUser();
Vocabulary voca = vocaCreator.createVocabulary(user);
vocaCreator.createTerms(voca, List.of(
new TermInfo("비빔밥", "비빔밥", List.of("비빔밥")),
new TermInfo("김치찌개", "김치찌개", List.of("김치찌개")),
new TermInfo("불고기", "불고기", List.of("불고기"))
));

SearchTermUseCase.Command command = SearchTermUseCase.Command.builder()
.userUid(user.getUid())
.vocabularyUids(List.of(voca.getUid()))
.query("김치찌개와 비빔밥, 그리고 불고기")
.build();

// when
SearchTermUseCase.Result result = searchTermUseCase.execute(command);

// then
assertThat(result.query()).isEqualTo("김치찌개와 비빔밥, 그리고 불고기");
assertThat(result.records())
.isNotEmpty()
.satisfiesExactlyInAnyOrder(
term -> {
assertThat(term.vocabularyUid()).isEqualTo(voca.getUid());
assertThat(term.hits()).hasSize(1);
assertThat(term.hits().getFirst().term()).contains("김치찌개");
assertThat(term.hits().getFirst().meaning()).contains("김치찌개");
assertThat(term.hits().getFirst().synonyms()).contains("김치찌개");
}
);
}
}

0 comments on commit 39e7e56

Please sign in to comment.