Skip to content

Commit

Permalink
test: QuestionRepository 질문 리스트 조회 테스트 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
623nana committed Aug 4, 2021
1 parent 51719bb commit 8f18ec8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.nexters.covid.letter.domain;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DataJpaTest
public class QuestionRepositoryTest {

@Autowired
QuestionRepository questionRepository;

@Test
@DisplayName("[QuestionRepository] 선택한 옵션에 따른 질문과 공통 질문 조회 테스트")
void findQuestionByOptionTest() {
List<Question> questions = questionRepository.findQuestionsBySendOptionIdEqualsOrSendOptionIdEquals(1L, 3L);

List<Long> sendOptionIds = questions.stream()
.map(q -> q.getSendOption().getId())
.collect(Collectors.toList());

assertThat(sendOptionIds.contains(1L)).isTrue();
assertThat(sendOptionIds.contains(3L)).isTrue();
}
}
5 changes: 5 additions & 0 deletions src/test/java/resources/data-h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ values ('ANSWER1', 'CONTENTS1', 'ENCRYPTED1', 'LETTER_TO1', 'email', 'A', 'BLUE'

insert into send_option (text, covid_stat) values ('테스트', 1000);
insert into send_option (text, covid_stat) values ('테스트2', 2000);
insert into send_option (text, covid_stat) values ('기본질문', 0);

insert into question (text, send_option_id) values ('테스트1에 1', 1);
insert into question (text, send_option_id) values ('테스트1에 2', 1);
insert into question (text, send_option_id) values ('테스트1에 3', 1);

insert into question (text, send_option_id) values ('테스트2에 1', 2);
insert into question (text, send_option_id) values ('테스트2에 2', 2);

insert into question (text, send_option_id) values ('기본 질문1', 3);
insert into question (text, send_option_id) values ('기본 질문2', 3);
insert into question (text, send_option_id) values ('기본 질문3', 3);

0 comments on commit 8f18ec8

Please sign in to comment.