Skip to content

Commit

Permalink
🐛 [MTA-2286] Don't count autoanswered questions when determining whet…
Browse files Browse the repository at this point in the history
…her an asessement has been started. (#716)

Fixes https://issues.redhat.com/browse/MTA-2286

---------

Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam committed Jul 10, 2024
1 parent 8bfd399 commit 0e52e70
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
13 changes: 12 additions & 1 deletion assessment/assessment.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (r *Section) Complete() bool {
// Started returns whether any questions in the section have been answered.
func (r *Section) Started() bool {
for _, q := range r.Questions {
if q.Answered() {
if q.Answered() && !q.AutoAnswered() {
return true
}
}
Expand Down Expand Up @@ -194,6 +194,17 @@ func (r *Question) Answered() bool {
return false
}

// AutoAnswered returns whether the question has had an
// answer pre-selected by the system.
func (r *Question) AutoAnswered() bool {
for _, a := range r.Answers {
if a.AutoAnswered {
return true
}
}
return false
}

// Tags returns any tags to be applied based on how the question is answered.
func (r *Question) Tags() (tags []CategorizedTag) {
for _, answer := range r.Answers {
Expand Down
114 changes: 114 additions & 0 deletions assessment/assessment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,117 @@ func TestPrepareSections(t *testing.T) {
g.Expect(questions[2].Answers[0].AutoAnswered).To(gomega.BeTrue())
g.Expect(questions[2].Answers[0].Selected).To(gomega.BeTrue())
}

func TestAssessmentStarted(t *testing.T) {
g := gomega.NewGomegaWithT(t)

assessment := Assessment{
Sections: []Section{
{
Questions: []Question{
{
Text: "S1Q1",
Answers: []Answer{
{
Text: "A1",
Selected: true,
},
{
Text: "A2",
},
},
},
{
Text: "S1Q2",
Answers: []Answer{
{
Text: "A1",
},
{
Text: "A2",
},
},
},
},
},
{
Questions: []Question{
{
Text: "S2Q1",
Answers: []Answer{
{
Text: "A1",
},
{
Text: "A2",
},
},
},
},
},
},
}
g.Expect(assessment.Started()).To(gomega.BeTrue())
g.Expect(assessment.Status()).To(gomega.Equal(StatusStarted))
assessment.Sections[0].Questions[0].Answers[0].AutoAnswered = true
g.Expect(assessment.Started()).To(gomega.BeFalse())
g.Expect(assessment.Status()).To(gomega.Equal(StatusEmpty))
}

func TestAssessmentComplete(t *testing.T) {
g := gomega.NewGomegaWithT(t)

assessment := Assessment{
Sections: []Section{
{
Questions: []Question{
{
Text: "S1Q1",
Answers: []Answer{
{
Text: "A1",
},
{
Text: "A2",
},
},
},
{
Text: "S1Q2",
Answers: []Answer{
{
Text: "A1",
Selected: true,
},
{
Text: "A2",
},
},
},
},
},
{
Questions: []Question{
{
Text: "S2Q1",
Answers: []Answer{
{
Text: "A1",
},
{
Text: "A2",
Selected: true,
AutoAnswered: true,
},
},
},
},
},
},
}
g.Expect(assessment.Complete()).To(gomega.BeFalse())
g.Expect(assessment.Status()).To(gomega.Equal(StatusStarted))
assessment.Sections[0].Questions[0].Answers[0].Selected = true
g.Expect(assessment.Complete()).To(gomega.BeTrue())
g.Expect(assessment.Status()).To(gomega.Equal(StatusComplete))
}

0 comments on commit 0e52e70

Please sign in to comment.