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

🐛 Questionnaire validation should tolerate order fields having value 0 #575

Merged
merged 1 commit into from
Dec 7, 2023
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
10 changes: 5 additions & 5 deletions assessment/assessment.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (r *Assessment) Confidence() (score int) {
//
// Section represents a group of questions in a questionnaire.
type Section struct {
Order uint `json:"order" yaml:"order" binding:"required"`
Order *uint `json:"order" yaml:"order" binding:"required"`
Name string `json:"name" yaml:"name"`
Questions []Question `json:"questions" yaml:"questions" binding:"dive"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
Expand Down Expand Up @@ -179,11 +179,11 @@ func (r *Section) Tags() (tags []CategorizedTag) {
//
// Question represents a question in a questionnaire.
type Question struct {
Order uint `json:"order" yaml:"order" binding:"required"`
Order *uint `json:"order" yaml:"order" binding:"required"`
Text string `json:"text" yaml:"text"`
Explanation string `json:"explanation" yaml:"explanation"`
IncludeFor []CategorizedTag `json:"includeFor,omitempty" yaml:"includeFor,omitempty" binding:"excluded_with=ExcludeFor"`
ExcludeFor []CategorizedTag `json:"excludeFor,omitempty" yaml:"excludeFor,omitempty" binding:"excluded_with=IncludeFor"`
IncludeFor []CategorizedTag `json:"includeFor,omitempty" yaml:"includeFor,omitempty"`
ExcludeFor []CategorizedTag `json:"excludeFor,omitempty" yaml:"excludeFor,omitempty"`
Answers []Answer `json:"answers" yaml:"answers" binding:"dive"`
}

Expand Down Expand Up @@ -224,7 +224,7 @@ func (r *Question) Tags() (tags []CategorizedTag) {
//
// Answer represents an answer to a question in a questionnaire.
type Answer struct {
Order uint `json:"order" yaml:"order" binding:"required"`
Order *uint `json:"order" yaml:"order" binding:"required"`
Text string `json:"text" yaml:"text"`
Risk string `json:"risk" yaml:"risk" binding:"oneof=red yellow green unknown"`
Rationale string `json:"rationale" yaml:"rationale"`
Expand Down
14 changes: 9 additions & 5 deletions test/api/questionnaire/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ var (
RiskMessages: assessment.RiskMessages{},
Sections: []assessment.Section{
{
Order: 1,
Order: uint2ptr(1),
Name: "Section 1",
Questions: []assessment.Question{
{
Order: 1,
Order: uint2ptr(1),
Text: "What is your favorite color?",
Explanation: "Please tell us your favorite color.",
Answers: []assessment.Answer{
{
Order: 1,
Order: uint2ptr(1),
Text: "Red",
Risk: "red",
},
{
Order: 2,
Order: uint2ptr(2),
Text: "Green",
Risk: "green",
},
{
Order: 3,
Order: uint2ptr(3),
Text: "Blue",
Risk: "yellow",
Selected: true,
Expand All @@ -47,3 +47,7 @@ var (
}
Samples = []api.Questionnaire{Questionnaire1}
)

func uint2ptr(u uint) *uint {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should use https://pkg.go.dev/github.com/gotidy/ptr instead of writing our own?

return &u
}
Loading