Skip to content

Commit

Permalink
test: image questions are parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed Apr 16, 2024
1 parent a3b59f0 commit 7d702cd
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void setUp() {
defaultQuestion = Question.builder()
.id(1L)
.answers(new ArrayList<>())
.content("What is the capital of France?")
.questionCategory(QuestionCategory.GEOGRAPHY)
.type(QuestionType.TEXT)
.build();
Expand All @@ -60,6 +61,7 @@ void setUp() {
.text("Paris")
.category(AnswerCategory.CAPITAL_CITY)
.questions(List.of(defaultQuestion))
.language("en")
.questionsWithThisAnswer(List.of(defaultQuestion))
.build();

Expand Down Expand Up @@ -104,13 +106,29 @@ void testGetRandomQuestion() {

assertEquals(response.getId(), defaultResponseDto.getId());
}

@Test
void testGetRandomQuestionImageType() {
defaultQuestion.setType(QuestionType.IMAGE);
defaultQuestion.setContent("What is the capital of France?#* &%https://www.example.com/image.jpg");
when(questionRepository.findRandomQuestion(any(),any())).thenReturn(defaultQuestion);
QuestionResponseDto response = questionService.getRandomQuestion("en");
defaultResponseDto.setType(QuestionType.IMAGE);
defaultResponseDto.setImage("https://www.example.com/image.jpg");
assertEquals(response, defaultResponseDto);
}

@Test
void testGetRandomQuestionAnswersNotYetLoaded() {
when(questionRepository.findRandomQuestion(any(),any())).thenReturn(defaultQuestion);
defaultQuestion.setAnswers(List.of());
QuestionResponseDto response = questionService.getRandomQuestion("");

assertEquals(response.getId(), defaultResponseDto.getId());
QuestionResponseDto response = questionService.getRandomQuestion("en");
defaultResponseDto.setAnswers(List.of(AnswerResponseDto.builder()
.id(1L)
.category(AnswerCategory.CAPITAL_CITY)
.text("Paris")
.build()));
assertEquals(response, defaultResponseDto);
}
@Test
void testGetRandomQuestionNoQuestionsFound() {
Expand All @@ -122,7 +140,7 @@ void testGetQuestionById(){
when(questionRepository.findById(any())).thenReturn(Optional.of(defaultQuestion));
QuestionResponseDto response = questionService.getQuestionById(1L);

assertEquals(response.getId(), defaultResponseDto.getId());
assertEquals(response, defaultResponseDto);
}

@Test
Expand Down

0 comments on commit 7d702cd

Please sign in to comment.