Skip to content

Commit

Permalink
remove old version of API for multiple choice questions
Browse files Browse the repository at this point in the history
  • Loading branch information
the-vindex committed Dec 6, 2024
1 parent 9ba307b commit 8497250
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ public ResponseEntity<Boolean> answerQuestion(@PathVariable Integer id, @PathVar
return response(findQuestion(id).map(QuizQuestion.isCorrectAnswer(index)));
}

@Transactional
@PostMapping("/quiz-question/{id}/answer")
public ResponseEntity<Boolean> answerQuestionV2(@PathVariable Integer id, @RequestBody List<Integer> answers) {
int [] answersArray = answers.stream().mapToInt(Integer::intValue).toArray();
Optional<List<Integer>> wrongAnswers = findQuestion(id).map(QuizQuestion.getWrongAnswers(answersArray));
return response(Optional.of(wrongAnswers.get().isEmpty()));
}

@Transactional
@PostMapping("/quiz-question/{id}/answerv3")
public ResponseEntity<MultipleAnswersResult> answerQuestionV3(@PathVariable Integer id, @RequestBody List<Integer> answers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ public void answerQuestion(int answerIdx, boolean isCorrect) {
assertEquals(isCorrect, result);
}

public void answerQuestionV2(List<Integer> answerIdx, boolean isCorrect) {
var questionId = quizQuestionController.saveQuestion(createQuestion());

Boolean result = quizQuestionController.answerQuestionV2(questionId, answerIdx).getBody();

assertNotNull(result);
assertEquals(isCorrect, result);
}

@Test
public void answerQuestionV3_answerMultipleQuestionsCorrectly() {
checkMultipleAnswers(List.of(1,3), true, List.of());
Expand All @@ -86,31 +77,16 @@ private void checkMultipleAnswers(List<Integer> userAnswersIndexes, boolean isCo
MultipleAnswersResult result = quizQuestionController.answerQuestionV3(questionId, userAnswersIndexes).getBody();

assertNotNull(result);
// assertEquals(isCorrect, result.getQuestionAnsweredCorrectly());
assertEquals(isCorrect, result.getQuestionAnsweredCorrectly());

assertEquals(expectedWrongAnswers,result.getWrongAnswers());
}

@Test
public void answerQuestionCorrectly() {
public void answerSingleChoiceQuestionCorrectly() {
answerQuestion(1, true);
}

@Test
public void answerQuestionIncorrectly() {
answerQuestionV2(List.of(0), false);
}

@Test
public void answerMultipleQuestionsCorrectly() {
answerQuestionV2(List.of(1), true);
}

@Test
public void answerMultipleQuestionsIncorrectly() {
answerQuestionV2(List.of(0), false);
}

@Test
public void answerNonExistingQuestion() {
ResponseEntity<?> response = quizQuestionController.answerQuestion(-1, 0);
Expand Down

0 comments on commit 8497250

Please sign in to comment.