Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [MTA-2286] Don't count autoanswered questions when determining whether an asessement has been started. #716

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Loading