Reset answers slice when updating quiz

This commit is contained in:
andrea 2023-07-13 06:46:36 +02:00
parent 8652e738d5
commit dd4636a89d
2 changed files with 8 additions and 1 deletions

View file

@ -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)

View file

@ -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)
}
}