Browse Source

Reset answers slice when updating quiz

andrea 10 months ago
parent
commit
dd4636a89d
2 changed files with 8 additions and 1 deletions
  1. 4 0
      store/memory/memory.go
  2. 4 1
      store/memory/memory_test.go

+ 4 - 0
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)

+ 4 - 1
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)
 	}
 }