diff --git a/store/memory/memory.go b/store/memory/memory.go index 956a16e..9b52127 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -168,6 +168,10 @@ func (s *MemoryProboCollectorStore) createOrUpdateQuiz(r *client.CreateUpdateQui // Populate Question field quiz.Question = q + + // Reset answer slice + quiz.Answers = make([]*models.Answer, 0) + for i, answer := range r.Quiz.Answers { answerHash := hashes[i+1] a := s.getAnswerFromHash(answerHash) diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index c166b57..d386fa5 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -70,7 +70,7 @@ func (t *testSuite) TestUpdateQuiz() { Question: &client.Question{Text: "Updated question text."}, Answers: []*client.Answer{ {Text: "Answer 1", Correct: true}, - {Text: "Answer 2", Correct: false}, + {Text: "Updated Answer 2", Correct: false}, {Text: "Answer 3", Correct: false}, {Text: "Answer 4", Correct: false}, }, @@ -82,5 +82,8 @@ func (t *testSuite) TestUpdateQuiz() { if !t.Failed() { t.True(updated) t.True(createdQuizHash != updatedQuiz.Hash, "The two hashes should not be equal.") + t.Equal(4, len(updatedQuiz.Answers)) + t.Equal("Updated question text.", updatedQuiz.Question.Text) + t.Equal("Updated Answer 2", updatedQuiz.Answers[1].Text) } }