Reset answers slice when updating quiz
This commit is contained in:
parent
8652e738d5
commit
dd4636a89d
2 changed files with 8 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue