quiz resetc
This commit is contained in:
@@ -278,6 +278,24 @@ func TestQuiz_TakingFlow(t *testing.T) {
|
||||
t.Errorf("responses = %+v, %v", stats, err)
|
||||
}
|
||||
|
||||
// Staff can reset one participant: their attempt and answers go, the quiz
|
||||
// is pending for them again, and they can retake it from the start.
|
||||
if err := svc.ResetParticipant(ctx, quiz.ID, other); !errors.Is(err, repository.ErrQuizNotStarted) {
|
||||
t.Errorf("resetting someone with no attempt: %v, want ErrQuizNotStarted", err)
|
||||
}
|
||||
if err := svc.ResetParticipant(ctx, quiz.ID, user); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if card, _ := svc.Card(ctx, user, quiz.ID); card.My.State != model.QuizNotStarted {
|
||||
t.Errorf("state after reset = %s, want not_started", card.My.State)
|
||||
}
|
||||
if parts, _ := svc.Participants(ctx, quiz.ID); len(parts) != 0 {
|
||||
t.Errorf("participants after reset = %d, want 0", len(parts))
|
||||
}
|
||||
if again, err := svc.Start(ctx, user, quiz.ID); err != nil || again.Answered != 0 || again.Question == nil {
|
||||
t.Errorf("retaking after reset: %+v, %v", again, err)
|
||||
}
|
||||
|
||||
// Taken, so questions are frozen — but the title can still change.
|
||||
if _, err := svc.Update(ctx, quiz.ID, QuizDraft{Title: "x", Questions: []repository.QuestionInput{q("p", 0, "a", "b")}}); !errors.Is(err, ErrQuizLocked) {
|
||||
t.Errorf("editing questions after attempts: %v, want ErrQuizLocked", err)
|
||||
|
||||
Reference in New Issue
Block a user